• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to connect to MS SQL Server using JRun drivers

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have written a simple java code to connect to a MS sql server db.here is the code
import java.sql.*;
import java.io.*;
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";
try
{
Class.forName("allaire.jrun.jdbc.JRunDriver");
// 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)
{
e.printStackTrace();
}
}
}
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)
at createSecurityTable.main(createSecurityTable.java:14)
i have no idea why this is happening.
i have the jar file containing the driver in my classpath.
any help is greatly appreciated.
Subbu
[This message has been edited by Subbu Aswathanarayan (edited July 25, 2001).]
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is only one reason that I can think of and is that the class is not in your classpath. You may think it is but chances are it is not.
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

Trevor
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have a question.
can i connect to a MS sql server datbase without using a dsn.if yes how?a sample code would be great.
thanks.
Subbu
 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to give the connection a name, otherwise how would you know to retrieve the proper connection. I just made it a variable in my ServletContext to make it more dynamic. The name has to be the same as the name you gave the connection in JRun
Trevor
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi trevor,
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.
Subbu
 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Subbu
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
Trevor

[This message has been edited by Trevor Dunn (edited July 26, 2001).]
 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic