【发布时间】:2017-04-08 16:25:34
【问题描述】:
您好,我正在尝试使用 JDBC 连接到 mysql 数据库,我的代码如下。我收到一个错误,因此找不到合适的驱动程序。搜索我发现通常的错误是语法或缺少类路径中的 jar 文件。我尝试了这两种解决方案,但不知道下一步该怎么做,它无法连接。另外,为了管理我安装了 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();
}
}
}
【问题讨论】: