[英]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.