| Author |
MS SQL 2000 connection
|
Adam Dear
Greenhorn
Joined: Oct 21, 2003
Posts: 13
|
|
Hello all, I am trying to connect to a MS Sql Server database using the jdbc driver provided by MS. When I try to run the program, I get a ClassNotFoundException. Here is the line generating the exception: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); I have added the three .jar files that were installed to the classpath, but still get this error. I'm sure there is something simple that I am missing, but could someone please give me some advice. Here is the entire code for the problem: try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://myip:1433","uid","pwd"); Statement statement=connection.createStatement(); String query="select * from test.SHIPPING"; ResultSet resultSet = statement.executeQuery(query); while(resultSet.next()) { System.out.println("pn="+resultSet.getString(1).toString()+"sn="+resultSet.getString(2)); } } catch(Exception e) { System.out.println("Error with connection "+e.toString()); } Please give me any advice thanks -A
|
 |
Chris Hall
Ranch Hand
Joined: Dec 04, 2002
Posts: 39
|
|
|
A ClassNotFoundException at the line indicated means that the classpath is not set correctly, and not picking up the jar file containing com.microsoft.jdbc.sqlserver.SQLServerDriver. So...look into how you are setting your classpath and make sure the jar files are on it.
|
 |
Adam Dear
Greenhorn
Joined: Oct 21, 2003
Posts: 13
|
|
Thanks for the help. I went back and looked at my classpath, and found that I had left off the .jar extension of one of the files
|
 |
 |
|
|
subject: MS SQL 2000 connection
|
|
|