Help a student with JDBC problems please


2003-09-10 01:42:20 AM
jbuilder6
Hi everyone,
Okay im a student trying make what should be a simple program run.
Every time i run the appliation the driver cannot be found. I added a
bit of code that would show me what .jar files are being used, and the
ones i need are not being accessed. The code i used to see this is:
System.out.println("My classpath is " +
System.getProperty("java.class.path") );
Im using JBuilder3 which i got from school, im running it on WinXp
Prof. and im trying to connect to microsoft SQL 2000 server.
Im using the Microsoft sql server 2000 for JDBC driver.
My classpath that i set up in my computers enviormental variables
looks like this:
"c:\workdir\classes;C:\Microsoft SQL Server 2000 Driver for
JDBC\lib\mssqlserver.jar;C:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msbase.jar;C:\Microsoft SQL Server 2000 Driver for
JDBC\lib\msutil.jar"
Those ""'s are actually in there someone told me they need to be but i
dont know if this is correct or not.
My actual Java program looks like this:
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","sa");
p.put("password","tom");
Connection connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433",p );
//"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 );
}
}
Im getting the driver not found error message and it shows:
com.microsoft.jdbc.sqlserver.SQLServerDriver as the driver not found.
Im not sure if i have to set up some type of jar location inside of
JBuilder or what else i could possibly be doing wrong.
Thanks everyone for your help i really appreciate it!