wood burning stoves 2.0*
The moose likes JDBC and the fly likes Why JVM can't find my jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Why JVM can Watch "Why JVM can New topic
Author

Why JVM can't find my jdbc

Calvin Yan
Greenhorn

Joined: Jun 25, 2003
Posts: 19
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


I will do the best with what God gave me!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Jun 25, 2003
Posts: 19
I'm just building a stand-alone application.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

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?


Groovy
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Another way to figure it out (works with an IDE as well) is to add into your code.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Calvin Yan
Greenhorn

Joined: Jun 25, 2003
Posts: 19
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

Joined: May 22, 2003
Posts: 108
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


SCJP 1.2, SCJP 5, SCBCD
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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 ]

GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why JVM can't find my jdbc
 
Similar Threads
Problem with getConnection() after exporting project to a jar file
JDBC drivers
No suitable driver found
MS JDBC driver
How to establish JDBC Connection to SQL Server