Classpath Problems for JDBC, Please help a student

T

Tom

Hello everyone,

Im trying to run a simple program that connects to a local Microsoft
SQL 2000 server which is on my laptop.
I have stored the needed Jar files on my computers enviormental
variables but im still having connectivity issues.

i added this in my catch statements:

System.out.println("My classpath is " +
System.getProperty("java.class.path") );

to show if it is picking up my classpath and it is not.

The actual error i get is:

Driver not found: com.microsoft.jdbc.sqlserver.SQLServerDriver

ill post all the code below. If anyone has any suggestions they would
be greatly appreciated
Thanks for the help everyone.

package thomas;

import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;

public class displayAuthors extends JFrame {


public displayAuthors()
{
super( "Authors Table of Books Database" );


try {


Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver"
);

Properties p = new Properties();
p.put("selectMethod","cursor");
p.put("user","tom");
p.put("password","todd");

Connection connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://TOMLAP2:1433",p );


Statement statement = connection.createStatement();


ResultSet resultSet =
statement.executeQuery( "SELECT * FROM authors" );


StringBuffer results = new StringBuffer();
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();

for ( int i = 1; i <= numberOfColumns; i++ ) {
results.append( metaData.getColumnName( i )
+ "\t" );
}

results.append( "\n" );

while ( resultSet.next() ) {

for ( int i = 1; i <= numberOfColumns; i++ ) {
results.append( resultSet.getObject( i )
+ "\t" );
}

results.append( "\n" );
}


statement.close();
connection.close();


JTextArea textArea = new JTextArea(
results.toString() );
Container container = getContentPane();

container.add( new JScrollPane( textArea ) );

setSize( 300, 100 );
setVisible( true );
}

catch ( SQLException sqlException ) {
System.out.println("My classpath is " +
System.getProperty("java.class.path") );
JOptionPane.showMessageDialog( null,
sqlException.getMessage(), "Database Error",
JOptionPane.ERROR_MESSAGE );

System.exit( 1 );
}


catch ( ClassNotFoundException classNotFound ) {
System.out.println("My classpath is " +
System.getProperty("java.class.path") );
JOptionPane.showMessageDialog( null,
classNotFound.getMessage(), "Driver Not Found",
JOptionPane.ERROR_MESSAGE );

System.exit( 1 );
}
}


public static void main( String args[] )
{
displayAuthors window = new displayAuthors();

window.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
}
}
 
D

Dave Glasser

(e-mail address removed) (Tom) wrote on 29 Aug 2003 15:18:16 -0700 in
comp.lang.java.programmer:
Hello everyone,

Im trying to run a simple program that connects to a local Microsoft
SQL 2000 server which is on my laptop.
I have stored the needed Jar files on my computers enviormental
variables but im still having connectivity issues.

i added this in my catch statements:

System.out.println("My classpath is " +
System.getProperty("java.class.path") );

to show if it is picking up my classpath and it is not.

The actual error i get is:

Driver not found: com.microsoft.jdbc.sqlserver.SQLServerDriver

ill post all the code below. If anyone has any suggestions they would
be greatly appreciated
Thanks for the help everyone.

From your error message, it looks like you don't have the driver in
your classpath, even though you think you do. What is the name of the
jar or zip file that contains the drivers? Is the full path to the jar
file in your classpath instead of just the directory that contains it?
(it would have help if you would have posted your actual CLASSPATH
environment variable.) In other words, if the drivers jar file is at:

C:\lib\drivers.jar

Then your classpath should look something like:

C:\workdir\classes;C:\lib\drivers.jar
 
T

Tom

Dave Glasser said:
(e-mail address removed) (Tom) wrote on 29 Aug 2003 15:18:16 -0700 in
comp.lang.java.programmer:


From your error message, it looks like you don't have the driver in
your classpath, even though you think you do. What is the name of the
jar or zip file that contains the drivers? Is the full path to the jar
file in your classpath instead of just the directory that contains it?
(it would have help if you would have posted your actual CLASSPATH
environment variable.) In other words, if the drivers jar file is at:

C:\lib\drivers.jar

Then your classpath should look something like:

C:\workdir\classes;C:\lib\drivers.jar



----
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net




Im not really sure i understand.
I have my CLASSPATH enviormental variable set as

C:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msutil.jar;c:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msbase.jar;c:\Microsoft SQL Server 2000 Driver for
JDBC\lib\mssqlserver.jar

which is the path the the three jar files that the driver says it
needs.
Is this wrong?
 
T

Tom

Im not really sure i understand.
I have my CLASSPATH enviormental variable set as

C:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msutil.jar;c:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msbase.jar;c:\Microsoft SQL Server 2000 Driver for
JDBC\lib\mssqlserver.jar

which is the path the the three jar files that the driver says it
needs.
Is this wrong?

Is there anyone other way to set the classpath variable that anyone knows about?
 
T

Tom

Im not really sure i understand.
I have my CLASSPATH enviormental variable set as

C:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msutil.jar;c:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msbase.jar;c:\Microsoft SQL Server 2000 Driver for
JDBC\lib\mssqlserver.jar

which is the path the the three jar files that the driver says it
needs.
Is this wrong?

Is there anyone other way to set the classpath variable that anyone knows about?
 
D

Dave Glasser

(e-mail address removed) (Tom) wrote on 2 Sep 2003 06:54:43 -0700 in
comp.lang.java.programmer:
Im not really sure i understand.
I have my CLASSPATH enviormental variable set as

C:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msutil.jar;c:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msbase.jar;c:\Microsoft SQL Server 2000 Driver for
JDBC\lib\mssqlserver.jar

which is the path the the three jar files that the driver says it
needs.
Is this wrong?

It looks OK. This is a guess, but maybe the spaces in the directory
names are breaking something. If you're using Java 1.4.x, try using a
version of Java 1.3, because there's a glitch in the way 1.4 handles
filepaths with spaces that broke some of my code once. Or if you don't
want to download and install Java 1.3, make a directory called C:\jdbc
and move the jars to there, then change your classpath accordingly.
It's worth a shot. Please let me know if this fixes your problem.
 
Joined
Jul 27, 2007
Messages
1
Reaction score
0
Classpath Problems for JDBC

I struggled with this issue for a long time. I also figured my classpath was set up correctly, as the jar files were included in the IDE's classpath, under Tools-->Options-->Miscellaneous-->Ant-->Manage classpath.

But for anyone also struggeling with this issue, try the following - it worked for me:

Right click on your project folder and choose properties. Under libraries, choose the Compile tab, and add the three JCBC jar files there.

Sometimes the obvious is also overlooked. My old laptob has a weak network connection point and sometimes disconnects from the network! So check that too! Time for me to get a new laptop! :)

Hope this helps someone.
F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top