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 );
}
}
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 );
}
}