Driver problem
Posted by: amaru
Date: June 27, 2005 08:44AM

Hello,
I'm trying to make a connection to a local mysql database. I'm getting the following error:
*** initializing the database connection
creating the class com.mysql.jdbc.Driver ... java.lang.ClassNotFoundException: com.mysql.jdbc.Drivercom.mysql.jdbc.Driver
*** querying the database
java.lang.NullPointerException
I don't know why I'm getting this error. Is there anyone who can help me out here?
Here is my source code:

import java.io.*;
import java.sql.*;
import java.util.*;
import java.text.*;
import java.lang.reflect.*;


class MySQL_Query {


/* The Data you need for the connection */
protected final String dbUser = "testuser";
protected final String dbPassword = "testpw";
protected final String dbName = "testdb";


/* Data for the server and driver */
protected String jdbcURL_erde = "jdbc:mysql://localhost";
protected String jdbcDriver = "com.mysql.jdbc.Driver";

/* connection to the database */
protected Connection con = null;


public static void main(String args[])
{
MySQL_Query query = new MySQL_Query();
query.initConnection();

/* Example Query: works only with the company Database. */
query.salary_query();
}


/**
* Query to the Relation employee
*/

private void salary_query()
{
try {
System.out.println("*** querying the database");
/* String query =
"SELECT * FROM employee WHERE salary >= '30000'";*/
String query ="CREATE TABLE Verein (Verein_id CHAR(20), Land CHAR(20), Stadt CHAR(20), Name CHAR(20))";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
/* while (rs.next()) {
String fname = rs.getString(1);
String minit = rs.getString(2);
String lname = rs.getString(3);
String salary = rs.getString(8);
System.out.println(
"( " + fname + ", " + minit + ", " + lname +
", " + salary + " )" );
}*/
}
catch (Exception mye){
System.out.println(mye.toString());
}
}


/**
* Registration of the required JDBC drivers at the
* driver manager and installation of a database connection.
* Re-installation of a database connection.
*/


protected void initConnection()
{
try {
System.out.println("*** initializing the database connection");
System.out.print(
"creating the class " + jdbcDriver.toString() + " ... " );
Class.forName(jdbcDriver).newInstance();
System.out.println( "done" );
System.out.print(
"connecting to the database " + jdbcURL_erde + dbName + " ... " );
con = DriverManager.getConnection(
jdbcURL_erde + dbName, dbUser, dbPassword );
System.out.println( "done" );
}
catch (InstantiationException ie) {
System.out.println(ie + ie.getMessage());
}
catch (IllegalAccessException iae) {
System.out.println(iae + iae.getMessage());
}
catch (SQLException sqle) {
System.out.println(sqle + sqle.getMessage());
}
catch (ClassNotFoundException cnfe) {
System.out.println(cnfe + cnfe.getMessage());
}
}


}

Options: ReplyQuote


Subject
Written By
Posted
Driver problem
June 27, 2005 08:44AM
June 27, 2005 08:55AM
June 27, 2005 08:59AM
June 27, 2005 09:07AM


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.