what I use is SQL SERVER 2000,the system is WINXP SP-2
I set the classpath:C:\Borland\JBuilder2005\jdk1.4\lib;.;C:\Program Files\Tomcat 5.0\common\lib;.;
I use the JDBC-ODBC to connect the database,the original code is

package hospital.db;

import java.sql.*;
import hospital.db.*;

public abstract class DBConnection
{
private static Connection conn = null;
public static Connection getConnection()
{
try
{
if(conn == null)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:shujuku","sa","");
System.out.println("Connection created.");
}
else
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select count from administrator");
if(rs == null || !rs.next())
{
Class.forName("san.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:shujuku","sa","");
System.out.println("Connection re-created.");
}
}
catch(Exception ex)
{
System.out.println(ex);
}
finally
{
return conn;
}
}
}

there is no problem in connection the database:Connection created. 2006-04-12 11:34:33
but when I put it into the Tomcat 5.0,it always throw something like:
sun.jdbc.odbc.JdbcOdbc.createSQLException() Ln6958[Microsoft][ODBC SQL Server Driver]

Recommended Answers

All 3 Replies

Could you add a line to print the stack trace? ex.printStackTrace();

Try adding the following to the policy file:

grant {
    permission java.lang.RuntimePermission
       "accessClassInPackage.sun.jdbc.odbc";
    permission java.util.PropertyPermission
       "file.encoding", "read";
  };

the policy file is located under JRE_HOME lib/security

or tomcat may have its own, you will have to search for
a file with poilcy in the name under the tomcat base
directory

i think there will be problem with the odbc driver you have selected. test the DSN while ur creating. and there may also authendication problem. so check with authendication u have selected with sqlserver.

Its

Pon.logeswaran

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.