Question

I have a problem with connecting my java and mysql database was working fine yesterday but now is not working here is my code.

public static void main(String[] args) {


    try 
    {
        Class.forName ("com.mysql.jdbc.Driver");
    }
    catch (ClassNotFoundException e)
    {
        System.out.println ("Could not load the driver");
    }

    String user, pass, host, database;
    user = "Michael";
    pass = "Blaine22";
    host = "localhost";
    database = "maintenance_work";

    Connection conn = DriverManager.getConnection
            ("jdbc:mysql://"+host+":3306/"+database, user, pass);

    conn.setAutoCommit(false);


    //Menu code:
    appSchoolMaintenance newWork = new appSchoolMaintenance();
    newWork.statement1(); // opens the start method


}
Was it helpful?

Solution 3

Started to work again - tried all the suggestions but started working again no rhyme or reason to it! thanks for the help though

OTHER TIPS

Add MySQL JDBC driver (you can get it here: http://dev.mysql.com/downloads/connector/j/) to application's classpath and remove unnecessary piece of code:

    try 
    {
        Class.forName ("com.mysql.jdbc.Driver");
    }
    catch (ClassNotFoundException e)
    {
        System.out.println ("Could not load the driver");
    }

You can try to connect directly with MySQL JDBC driver

com.mysql.jdbc.Driver driver = new com.mysql.jdbc.Driver();
Connection conn = driver.
            connect("jdbc:mysql://localhost/test?user=root&password=root", null);

if this code does compile you are missing MySQL JDBC driver on the classpath

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top