Getting Connected for the First Time
Posted by: Rob Pete
Date: May 16, 2005 06:43PM

Hello everyone. I am trying to make my first database connection to a mysql database with Java. I am using jdk 1.5.0, MySQL 4.1.11 nt, and I think I have the freshly downloaded driver C:\jdk1.5.0\jre\lib\ext\mysql-connector-java-3.0.16-ga-bin.jar" installed in the right spot. When I try to run the following code...

package dbfinder;

import java.sql.*;
import javax.sql.*;
import com.sun.rowset.JdbcRowSetImpl;
import javax.sql.rowset.JdbcRowSet;
import java.sql.ResultSetMetaData;


/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class DatabaseConnector {
public DatabaseConnector() {

}

public static void main(String args[]){
Connection connection;
Statement statement;
// ResultSet resultSet;
// ResultSetMetaData metaData;
String DATABASE_DRIVER = "com.mysql.jdbc.Driver";
String DATABASE_URL = "jdbc:mysql://localhost/state_crime";
String USER = "cis695d";
String PASSWORD = "cis695d";
JdbcRowSet rowSet = new JdbcRowSetImpl();
try {
Class.forName(DATABASE_DRIVER); // load database driver
System.out.println("class loaded");
rowSet.setUrl("DATABASE_URL");
rowSet.setUsername(USER);
rowSet.setPassword(PASSWORD);
rowSet.setCommand("Select * FROM state_crime_rates");
rowSet.execute();

ResultSetMetaData metaData = rowSet.getMetaData();
int numberOfColumns;
numberOfColumns = metaData.getColumnCount();
System.out.println(numberOfColumns);

} catch(SQLException sqlException){
sqlException.printStackTrace();
System.exit(1);
}
catch(ClassNotFoundException classNotFound){
classNotFound.printStackTrace();
System.exit(1);
}




}
}

I get the following exception...

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.sun.rowset.JdbcRowSetImpl.connect(JdbcRowSetImpl.java:618)
at com.sun.rowset.JdbcRowSetImpl.prepare(JdbcRowSetImpl.java:630)
at com.sun.rowset.JdbcRowSetImpl.execute(JdbcRowSetImpl.java:526)
at dbfinder.DatabaseConnector.main(DatabaseConnector.java:44)

Does anyone have any ideas? Is it my code? Is there a different driver I should use? Any help would be greatly appreciated.

Options: ReplyQuote


Subject
Written By
Posted
Getting Connected for the First Time
May 16, 2005 06:43PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.