Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java.Lang.ClassNotFoundException: com.mysql.jdbc.Driver

843859Jun 5 2007 — edited Oct 13 2007
Hello Folk,

I'm writing a simple database using NetBean 5.5.1. The database is MySQL. When I tested my code, I got the error stated above in the Subject line. Please help me out here. Below is my code.

public class sharedConnection
{
// Declare variable to established a Connection to the DB
static String dataSource = "jdbc:mysql://localhost:3306/consumer";
static Connection aConnection;

// Custom method Initialize() - establish a connection to the DB
public static Connection Initialize()
{
try
{
//1: Load the MySQL driver to connect to the MySQL DB
Class.forName("com.mysql.jdbc.Driver");
// 2: Connect to the DB
aConnection = DriverManager.getConnection(dataSource,
"VuHua", "hailua911");
}
catch(ClassNotFoundException cnfe)
{ System.out.println(cnfe); }
catch(SQLException sqe)
{ System.out.println(sqe); }

// 3: Return the Connection
return aConnection;
}

// Custom method terminate() - close the DB connection & released resource
public static void terminate()
{
try
{ aConnection.close(); } // Close the DB Connection
catch(SQLException sqe)
{ System.out.println(sqe); }
}
}


public class Tester
{
public static void main(String[] args)
{
Connection connection = sharedConnection.Initialize();
Boat.Initialize(connection);

try
{
Boat aBoat = Boat.search("ABC12345");
System.out.println(aBoat.getStateRegistrationNo());
}
catch(NotFoundException nfe)
{ System.out.println(nfe); }

sharedConnection.terminate();
Boat.terminate();
}
}

Exception in thread "main" java.lang.NullPointerException
at Array.BoatDA.Initialize(BoatDA.java:41)
at Array.Boat.Initialize(Boat.java:32)
at Array.Tester.main(Tester.java:24)

Message was edited by:
Hailua

Message was edited by:
Hailua
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 10 2007
Added on Jun 5 2007
4 comments
374 views