can someone be kind enough ...

hello. i am trying to run a simple jdbc program. I have mysql4.1 installed. i have installed the mysql J connector also. i've set the classpath for the .jar file under eclipse also for the connector. i have created a username and password and have loaded the script also in mysql. but when i try to run an example program in eclipse it gives me classnotfoundexception. Help.

import java.sql.Connection;

import java.sql.Statement;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

publicclass DisplayAuthors

{

// JDBC driver name and database URL

staticfinal String JDBC_DRIVER ="com.mysql.jdbc.Driver";

staticfinal String DATABASE_URL ="jdbc:mysql://localhost/books";

// launch the application

publicstaticvoid main( String args[] )

{

Connection connection =null;// manages connection

Statement statement =null;// query statement

// connect to database books and query database

try

{

Class.forName( JDBC_DRIVER );// load database driver class

// establish connection to database

connection =

DriverManager.getConnection( DATABASE_URL,"jhtp6","jhtp6" );

// create Statement for querying database

statement = connection.createStatement();

// query database

ResultSet resultSet = statement.executeQuery(

"SELECT authorID, firstName, lastName FROM authors" );

// process query results

ResultSetMetaData metaData = resultSet.getMetaData();

int numberOfColumns = metaData.getColumnCount();

System.out.println("Authors Table of Books Database:" );

for (int i = 1; i <= numberOfColumns; i++ )

System.out.printf("%-8s\t", metaData.getColumnName( i ) );

System.out.println();

while ( resultSet.next() )

{

for (int i = 1; i <= numberOfColumns; i++ )

System.out.printf("%-8s\t", resultSet.getObject( i ) );

System.out.println();

}// end while

}// end try

catch ( SQLException sqlException )

{

sqlException.printStackTrace();

System.exit( 1 );

}// end catch

catch ( ClassNotFoundException classNotFound )

{

classNotFound.printStackTrace();

System.exit( 1 );

}// end catch

finally// ensure statement and connection are closed properly

{

try

{

statement.close();

connection.close();

}// end try

catch ( Exception exception )

{

exception.printStackTrace();

System.exit( 1 );

}// end catch

}// end finally

}// end main

}// end class DisplayAuthors

and here is the error

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:164)

at deitel.DisplayAuthors.main(DisplayAuthors.java:25)

[5750 byte] By [schumachera] at [2007-11-27 10:39:45]
# 1

Then you haven't set the classpath correctly.

You're using Eclipse? Rightclick project, properties, Java Build Path, Libraries, add the Connector/J JAR to the listing.

BalusCa at 2007-7-28 19:02:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Hellzzzzzzzzzzz yeaaaaaaaaaaaa I got it. Thanks BALU :)))))))))))))))))))) working.

schumachera at 2007-7-28 19:02:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...