Hello all, I am having problems setting up a connection with a mysql database that i'm going to need to use for one of my projects. My code to establish the connection is as follows:

import java.sql.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.ResultSet;
import javax.sql.ConnectionEvent;
import java.sql.DriverManager;

public class SQL {

static String DRIVER = "com.mysql.jdbc.Driver";
static String DATABASE_URL = "jdbc:mysql:://mysql.ee.port.ac.uk:3306/ece00249";
static String UNAME = "ece00249";
static String PW = ".......";
static Connection conn = null;
static String database = "ece00249";
Statement statement = null;
ResultSet Rs = null;
public static void main(String[] args){
try{
Class.forName(DRIVER);
conn = DriverManager.getConnection(DATABASE_URL, UNAME, PW);
throw new SQLException ("database not reached");
}
catch(ClassNotFoundException e){
System.out.print(e);
}
catch(Exception e){
System.out.print(e);
}
}
}

I am getting the following error:

C:\java\database>java SQL
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I have got the mysql-connector-java-5.1.19-bin.jar file in several locations, Where SQL.java is, inside my \bin directories linking to my classpath.

What am i doing wrong?

You need to use a classpath with the jar file containing the missing class.
java -cp .;mysql-connector-java-5.1.19-bin.jar SQL

That seems to have done the trick! thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.