| | |
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
![]() |
Hi All,
I'm trying to use jdbc connection with sqlServer 2000. I'm using j2sdk1.4.2. And i have service pack2.
I've installed the .jar files mssqlserver.jar, msutil.jar, msbase.jar.
I have these jar files in E:\j2sdk1.4.2_04\lib.
I'm trying to connect with the following program.
when i compile i'm not getting any error...
but when i run it .. i'm getting this error...
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Connect.getConnection(Connect.java:28)
at Connect.displayDbProperties(Connect.java:46)
at Connect.main(Connect.java:82)
Error Trace in getConnection() : com.microsoft.jdbc.sqlserver.SQLServerDriver
Error: No active Connection
I'd be greatful if anyone can help me come out of this
I'm trying to use jdbc connection with sqlServer 2000. I'm using j2sdk1.4.2. And i have service pack2.
I've installed the .jar files mssqlserver.jar, msutil.jar, msbase.jar.
I have these jar files in E:\j2sdk1.4.2_04\lib.
I'm trying to connect with the following program.
Java Syntax (Toggle Plain Text)
import java.*; import java.io.*; 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= "master"; private final String userName = "Z"; private final String password = ""; // 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{ // Driver d = (Driver)Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 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(); } }
when i compile i'm not getting any error...
but when i run it .. i'm getting this error...
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Connect.getConnection(Connect.java:28)
at Connect.displayDbProperties(Connect.java:46)
at Connect.main(Connect.java:82)
Error Trace in getConnection() : com.microsoft.jdbc.sqlserver.SQLServerDriver
Error: No active Connection
I'd be greatful if anyone can help me come out of this
Last edited by stackOverflow; Sep 29th, 2008 at 2:08 am.
Imagination was given to man to compensate him for what he is not; A sense of humour to console him for what he is..
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#2 Sep 29th, 2008
Include the driver jarfile on your classpath.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#3 Sep 29th, 2008
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#4 Sep 29th, 2008
If so, then not correctly, or you misspelled the class or package name.
A ClassNotFoundException will only occur in one of three instances:
1. The Class is not anywhere on the CLASSPATH
2. The Class name is misspelled (which, essentially, falls back to #1)
3. The package "path" is wrong/misspelled (which also, essentially, falls back to #1)
Edit: Also, do not rely on the System CLASSPATH environment variable, containers won't use it. If running from a container, then include the library either in the common/lib or shared/lib (or equivalent depending on the server) or the WEB-INF/lib directory, or include a reference to it in the Manifest file when running from a jar (using -jar) or use the -cp command line option. (When running from an IDE, add it as an external library/jar in the project properties.)
A ClassNotFoundException will only occur in one of three instances:
1. The Class is not anywhere on the CLASSPATH
2. The Class name is misspelled (which, essentially, falls back to #1)
3. The package "path" is wrong/misspelled (which also, essentially, falls back to #1)
Edit: Also, do not rely on the System CLASSPATH environment variable, containers won't use it. If running from a container, then include the library either in the common/lib or shared/lib (or equivalent depending on the server) or the WEB-INF/lib directory, or include a reference to it in the Manifest file when running from a jar (using -jar) or use the -cp command line option. (When running from an IDE, add it as an external library/jar in the project properties.)
Last edited by masijade; Sep 29th, 2008 at 5:03 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 0
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#5 Feb 8th, 2009
Hi,
I have my class path setup and i'm still getting this errror.
I am using eclips and jsp.
here is a paste of my class path:
C:\Program Files\Java\jre6\lib;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;.
and my install directory:
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib
I did copy them into:
C:\tomcat\webapps\Reporting\WebContent\WEB-INF\lib
my java direcories are:
C:\Program Files\Java\jdk
C:\Program Files\Java\jre6
where Reporting is the project name.
any advice would be great.
thanks.
p.s. I'm on a vista laptop.
I have my class path setup and i'm still getting this errror.
I am using eclips and jsp.
here is a paste of my class path:
C:\Program Files\Java\jre6\lib;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;.
and my install directory:
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib
I did copy them into:
C:\tomcat\webapps\Reporting\WebContent\WEB-INF\lib
my java direcories are:
C:\Program Files\Java\jdk
C:\Program Files\Java\jre6
where Reporting is the project name.
any advice would be great.
thanks.
p.s. I'm on a vista laptop.
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 0
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#6 Feb 8th, 2009
I have writen a simple test using the java compiler and I get the this result.
import java.util.*;
import java.text.*;
import java.sql.*;
import java.io.*;
import java.*;
class test
{
public static void main(String args[]){
System.out.print("Start");
try
{
Connection conn = null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://DESKTOP;databasename=cssd_reporting_tool","sa","05330921");
Statement command = conn.createStatement();
String fieldSelectStatement = "SELECT * FROM tblUsers where UserName='nxc018'";
ResultSet rs = command.executeQuery(fieldSelectStatement);
rs.next();
System.out.print("OK");
System.out.print(rs.getString(2));
conn.close();
}
catch(SQLException sqle)
{
System.out.print(sqle.getMessage());
System.out.print("Sql error");
}catch(ClassNotFoundException cnfe){
System.out.print(cnfe.getMessage());
System.out.print("class not found error");
}
System.out.print("finnish");
}
}
C:\>java test
Start[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.Sql errorfinnish
C:\>
import java.util.*;
import java.text.*;
import java.sql.*;
import java.io.*;
import java.*;
class test
{
public static void main(String args[]){
System.out.print("Start");
try
{
Connection conn = null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://DESKTOP;databasename=cssd_reporting_tool","sa","05330921");
Statement command = conn.createStatement();
String fieldSelectStatement = "SELECT * FROM tblUsers where UserName='nxc018'";
ResultSet rs = command.executeQuery(fieldSelectStatement);
rs.next();
System.out.print("OK");
System.out.print(rs.getString(2));
conn.close();
}
catch(SQLException sqle)
{
System.out.print(sqle.getMessage());
System.out.print("Sql error");
}catch(ClassNotFoundException cnfe){
System.out.print(cnfe.getMessage());
System.out.print("class not found error");
}
System.out.print("finnish");
}
}
C:\>java test
Start[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.Sql errorfinnish
C:\>
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#7 Feb 8th, 2009
That is not the same error.
For that one, make sure that your SQL Server is setup to respond to TCP IP connection attempts (per default, it is, AFAIK, not).
For that one, make sure that your SQL Server is setup to respond to TCP IP connection attempts (per default, it is, AFAIK, not).
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 0
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#8 Feb 8th, 2009
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#9 Feb 8th, 2009
Reread the last sentence (the one in parenthesis) of reply #4.
Also, reread the part of that same post that says not to rely on the system CLASSPATH environment variable as containers (of which all IDEs are) will not use it.
Also, reread the part of that same post that says not to rely on the system CLASSPATH environment variable as containers (of which all IDEs are) will not use it.
Last edited by masijade; Feb 8th, 2009 at 7:38 pm.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 0
Re: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
0
#10 Feb 8th, 2009
![]() |
Similar Threads
- JDBC Driver for SQL Server 2005, Class not found Exception (Java)
- Sql + Java (Java)
- hi,urgent (Java)
- hi,urgent-jdbc doubt (MS SQL)
Other Threads in the Java Forum
- Previous Thread: Runtime.getRuntime().exec(a resource in a runnable jar+" "+other stuff);
- Next Thread: acc program help
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






