java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
- From: Sam Benson <whissper@xxxxxxxxxxxx>
- Date: Mon, 25 Jul 2005 00:05:14 +1000
Hello
This is really irritating.
Trying to connect to an SQL Server 2000 database using MS SQL JDBC (the MS implementation).
Keep getting the above error and I have checked CLASSPATH repeatedly to make sure msbase.jar, mssqlserver.jar and msutil.jar are listed in it. Have copied the relevant jars to working directory with no success. All I am trying to do is gain a connection to the database. I have googled around and cannot find much to help. The basic response issue seems to be a missing class but I am sure that CLASSPATH is set properly.
My CLASSPATH is c:\j2sdk1.4.2_07\lib;C:\Program Files\Microsoft SQL Server JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server JDBC\lib\msutil.jar
The class compiles but will not execute.
What am I missing?
Thanks
Sam Benson
The code is as follows (straight from MS website): <code> import java.*; public class Connect{ private java.sql.Connection con = null; private final String url = "jdbc:microsoft:sqlserver://"; private final String serverName= "localhost"; private final String portNumber = "1433"; //private final String databaseName= "ABADAT"; private final String databaseName= ""; private final String userName = "sa"; private final String password = "secret"; // Informs the driver to use server a side-cursor, // which permits more than one active statement // on a connection. private final String selectMethod = "cursor";
// Constructor
public Connect(){}private String getConnectionUrl(){
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
}
private java.sql.Connection getConnection(){
try{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
return con;
}
/*
Display the driver properties, database details
*/public void displayDbProperties(){
java.sql.DatabaseMetaData dm = null;
java.sql.ResultSet rs = null;
try{
con= this.getConnection();
if(con!=null){
dm = con.getMetaData();
System.out.println("Driver Information");
System.out.println("\tDriver Name: "+ dm.getDriverName());
System.out.println("\tDriver Version: "+ dm.getDriverVersion ());
System.out.println("\nDatabase Information ");
System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName());
System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion());
System.out.println("Avalilable Catalogs ");
rs = dm.getCatalogs();
while(rs.next()){
System.out.println("\tcatalog: "+ rs.getString(1));
}
rs.close();
rs = null;
closeConnection();
}else System.out.println("Error: No active Connection");
}catch(Exception e){
e.printStackTrace();
}
dm=null;
}
private void closeConnection(){
try{
if(con!=null)
con.close();
con=null;
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception
{
Connect myDbTest = new Connect();
myDbTest.displayDbProperties();
}
}
</code>
.- Follow-Ups:
- Re: java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
- From: Alan Krueger
- Re: java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
- Prev by Date: Re: Drawing translucent masks
- Next by Date: Re: java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
- Previous by thread: parsing XML files with SAX
- Next by thread: Re: java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
- Index(es):
Relevant Pages
|