• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why JVM can't find my jdbc

 
Calvin Yan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have installed SqlServer2000 jdbc in my machine, set classpath as following:
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;c:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar
But when I run the codes like :
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection c = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;User=administrator;Password=calvin");
}
catch(Exception e)
{
System.out.println(e.toString());
}
I always get the following exception:
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
Could anyone help me? thanks
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you building a stand-alone application or using an application server?
If you're using an application server, you need to include the jar file in (for example) the web-inf/lib directory for it to be visible in a web application.
Dave
 
Calvin Yan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just building a stand-alone application.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just do set CLASSPATH at the command prompt to see whether the jar files are set in the CLASSPATH .Just a verification
Are you using any IDE?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way to figure it out (works with an IDE as well) is to add into your code.
 
Calvin Yan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Lasse,
I tried the ways you teached me, and there is no jdbc setting in it. I don't know why. I really set classpath in my operation system, but it looks different from what I printed by using {System.getProperty("java.class.path")}. Where can I set that variable?
Thanks for teaching.
 
Chris Brat
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
quick thought?
when you run your app from the command line, do you include the driver jar in the -classpath option?
something like
java -cp driverjar.jar MainClass

try that
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calvin Y.
Hey buddy! I need you to do me a favor. Could you change your display name to meet our Naming Policy. The policy does not allow First Name Last Initial. But it does allow First Initial Last Name. For example, you could change it to Y. Calvin.
Thanks partner. Hope to see more of you around the Ranch.
BTW - You can change your display name here
See you around.
[ August 21, 2003: Message edited by: Gregg Bolinger ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic