I have written a simple java code to connect to a MS sql server db.here is the code
public class createSecurityTable
public static void main(String args) throws SQLException
String username = "aswaths";
String password = "cufs1";
String url = "jdbc:jrun:sqlserver://servername:1433;databaseName=db";
// Establish Connection to the database at URL with usename and password
Connection conn = DriverManager.getConnection(url, username, password);
System.out.println ("Ok, connection to the DB is working.");
catch(Exception e) // (ClassNotFoundException and SQLException)
i am not getting any compilation error but i am getting this error message while running it.
Exception in thread "main" java.lang.NoClassDefFoundError: allaire/jrun/servlet/JRunSE
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
i have no idea why this is happening.
i have the jar file containing the driver in my classpath.
any help is greatly appreciated.
[This message has been edited by Subbu Aswathanarayan (edited July 25, 2001).]
On a side note I also have used JRun and what I did was to declare my db connection inside of JRun under the JDBC datasources of the Default Server. If you do this you can get a connection by using the following code in your servlet
This way you do not have the datasource hardcoded into the application, and it could change. I had no problems with this method. Just make sure that the drivers are in the classpath for the default and admin servers
Check out the JRun docs. They explain it pretty good
but i do have a db name right.cant i connect to a ms sql server using the JDBC-ODBC bridge without creating a dsn for it.just as we do with 3rd party JDBC drivers for ms sql server.everything is going to be the same here, except for the driver.
i hope i am clear now.
I think I know where you are coming from now. A long while ago I played with connecting to MS SQL Server and had some problems also. You can do two things to connect to this server.
1. Set up a DSN in your ODBC administrator and use the JDBC:ODBC bridge to connect. You have to have a DSN set in your ODBC administrator to use the bridge
2. Use a third party driver to connect. I used JTurbo. This will allow you to connect through a URL, similar to the Oracle thin driver.
I warn you though that these third party drivers can cost a lot of money. Goto http://industry.java.sun.com/products/jdbc/drivers to find a list of drivers for MS SQL you may find a free one.
I just read the docs in JRun on using their drivers and they recommend that you create the connection in The Management Console and then use JNDI to retrieve the Connection based on the logical name of the database. To retrieve the connection is the same as the code I posted before. I will quote the JRun docs here for you
Calling Data Sources in an Application
Applications can call a JRun JDBC data source using a logical name to retrieve the javax.sql.DataSource object. This object loads the JRun JDBC driver and establishes the connection to the underlying database. Once a JRun JDBC data source has been registered with JNDI, it can be used by your JDBC application as shown in the following example:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(�jdbc/EmployeeDB�);
Connection con = ds.getConnection(�scott�, �tiger�);
In this example, the JNDI environment is first initialized. Next, the initial naming context is used to find the logical name of the JRun JDBC data source (EmployeeDB). The Context.lookup() method returns a reference to a Java object, which is narrowed to a javax.sql.DataSource object. Finally, the DataSource.getConnection() method is called to establish a connection with the underlying database.
To create the connection in JMC just follow the wizard, it is straightforward.
I hope this helps
[This message has been edited by Trevor Dunn (edited July 26, 2001).]