Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MS SQL 2000 connection

 
Adam Dear
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic