简体   繁体   中英

JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting

Hello im trying to connect to a mysql database using JDBC my code is below.I get an error as such No suitable driver found.Searching around I found that the usual error is syntax or missing the jar file from the class path.I tried both of these solutions and dont know what to do next it wont connect.Also to manage the databases I have WAMP and mySQL workbench installed not sure if its related.

package test.jdbc;
import java.sql.*;


public class jdbctester {

public static void main(String[] args)
{

    try
    {
        Connection myconn=DriverManager.getConnection("jdbc:mysql://localhost:3306/voting","root","Vanquish123");
        Statement myStmt=myconn.createStatement();
        ResultSet myRs=myStmt.executeQuery("select * from electoral");
        /*
        while(myRs.next())
        {
            System.out.println(myRs.getString("state")+","+myRs.getString("perDem"));
        }
        */
    }
    catch(Exception exc)
    {
    exc.printStackTrace();  
    }
}

}

Try this:

Class.forName("fully qualified driver class name");

Java Class.forName, JDBC connection loading driver

this post states that you should not need it but it will not hurt you to try.

you have to add "com.mysql.jdbc_5.1.5.jar" in to your project build path... go to project property>build Path> library> add external jar and add jar file.

Connection conn = null;  
    try {
        // Register JDBC driver
        Class.forName(DRIVER).newInstance();

        // Open a connection
        conn = DriverManager.getConnection(Local_URL + , USERNAME, PASSWORD);
        System.out.println("Connected Database Successfully...\n\n");

    } catch (Exception se) {
        throw new AppException("Failed to create Local Database connection", se);
    }
    return conn;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM