简体   繁体   English

JDBC JAVA找不到适合的驱动程序jdbc:mysql:// localhost:3306 / voting

[英]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. 你好,我试图使用JDBC连接到mysql数据库,我的代码如下。这些解决方案,不知道下一步该怎么做,它也不会连接。还要管理数据库,我安装了WAMP和mySQL工作台,不确定是否相关。

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"); Class.forName(“完全限定的驱动程序类名称”);

Java Class.forName, JDBC connection loading driver Java Class.forName,JDBC连接加载驱动程序

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. 您必须在项目构建路径中添加“ com.mysql.jdbc_5.1.5.jar”。转到项目属性>构建路径>库>添加外部jar并添加jar文件。

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发现此错误“没有找到适合 jdbc:mysql//localhost:3306/student 的驱动程序” - Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student" 如何解决:找不到适合jdbc的驱动:mysql://localhost:3306/sampledb - How to solve: No suitable driver found for jdbc:mysql://localhost:3306/sampledb 错误:找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - ERROR: No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / jpa的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/ jpa 找不到适用于jdbc:mysql // localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql//localhost:3306/test 找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql / localhost:3306 / world的驱动程序 - No suitable driver found for jdbc:mysql/localhost:3306/world Eclipse - Hibernate:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / hibernatedb - Eclipse - Hibernate : No suitable driver found for jdbc:mysql://localhost:3306/hibernatedb 找不到适用于jdbc:mysql // localhost:3306 / demo的驱动程序吗?useSSL = false - No suitable driver found for jdbc:mysql//localhost:3306/demo?useSSL=false SQLException:找不到适用于jdbc:mysql:// localhost:3306 / dbname的驱动程序 - SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbname
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM