Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Tomcat 5 and sqlserver 1

Status
Not open for further replies.

webcats

Programmer
Apr 24, 2002
60
US
Hi all,

I'm trying to connect to a sqlserver database with Tomcat 5.0. I've taken over a project which someone else built and I'm having problems.

In my server.xml file I have this:

<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="com.microsoft.jdbc.sqlserver.SqlServerDriver"
connectionURL="jdbc:microsoft:sqlserver://server-west:1433;databasename=dbcal;SelectMethod=cursor"
connectionName="dbcal" connectionPassword="dbcal"
userTable="users" userNameCol="user_name" userCredCol="password"
userRoleTable="user_roles" roleNameCol="role" />

I have downloaded and installed the sqlserver driver from ms and copied it into the Tomcat 5.0\common\lib folder (and also to the Tomcat 5.0\shared\lib folder just for good measure).

I created an application role in sqlserver with the username and password of "dbcal". I've given access to the tables also.

And I'm getting the error:

2004-10-07 13:09:58 JDBCRealm[Catalina]: Exception opening database connection
java.sql.SQLException: com.microsoft.jdbc.sqlserver.SqlServerDriver
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:589)
at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:663)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1075)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
at org.apache.catalina.core.StandardService.start(StandardService.java:480)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:284)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:422)

Can anyone point me in the right direction?

Thanks.
 
It's alway amused me how java exceptions can give you *so* *much* information without actually being useful. ;-)

Good error reporting is a hallmark of good programming.
 

I know exactly what you mean! It's very frustrating...
 
The easiest way to test the problem is to run a simple standalone test using the config params you have in your server.xml.

Code:
public void Test {
  public static void main(String args[]) throws Exception {
    Class.forName("com.microsoft.jdbc.sqlserver.SqlServerDriver");
    Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://server-west:1433;databasename=dbcal;SelectMethod=cursor", "userName", "password");
    System.out.println("Got connection : " +conn);
  }
}

I have heard that the conn string :

jdbc:microsoft:sqlserver://server-west:1433;databasename=dbcal;SelectMethod=cursor

sometimes should be chnaged to :
jdbc:microsoft:sqlserver://server-west:1433

but you need to try it ...

--------------------------------------------------
Free Database Connection Pooling Software
 

Thanks sedj, but I get a compile error for that code:

'class' or 'interface' expected

what did I do wrong?
 
Never mind... I'm brain dead this morning.
 
sedj,

I get this error:

java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SqlServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)


I don't understand... is the driver bad?

 
I got it. Like I said, I'm brain-dead this morning...

Thanks!
 
Glad you got it sorted.

Would you mind posting the correct JDBC URL for MSSQLServer & the solutiuon, so that other people can know.

Cheers !

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top