I designed a user interface using
java and at this point I am trying to connect it to a mySQL database on my computer just for development purposes. After that is complete I will be putting the database on a server and running it from there.
In the meantime I can't seem to find the right url to put into the Class.forName() call so my database is not actually connecting (keeps throwing the ClassNotFoundException). I commented out a few of the other urls I tried to use....all your help would be greatly appreciated...the connection class code is below:
(For reference I installed the mysql-connector-java-3.1.10 version)
import java.sql.*;
public class Connect {
public static void main(
String argv[]) {
Connection con = null;
Connection connection = null;
try {
//Load the
JDBC driver
//String driverName = "mysql-connector-java-3.1.10//src//com//mysql//jdbc//Driver"; //MySQL MM JDBC driver
//mm.mysql.jdbc.Driver
String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName).newInstance();
//Create a connection to the database
String serverName = "localhost";
String mydatabase = "prop";
String url = "jdbc:mysql:" + serverName + "/" + mydatabase; //a JDBC url
String username = "username";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
} catch (SQLException e) {
//Could not connect to the database
System.out.println("Connection Not Found");
}
catch (ClassNotFoundException e) {
System.out.println("Driver Not Found");
//Could not find the database driver}}
}
catch (Exception ex){
System.out.println("ex");
}
System.out.println("Connection:" + connection);
}
}