• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MS SQL 2000 connection

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic