0

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?

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by tleverington1
0

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

Edited by NormR1

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.