JAVAsql。SQLException:找不到适合jdbc的驱动程序:mysql://localhost:3306/asd性爱
import java.sql.*;
class Mysqll{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc::mysql://localhost:3306/asd","root","qwerty");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from abc");
while(rs.next())
{
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
我是jdbc编程新手。所以请帮忙。 运行程序时获取此异常
java.sql.SQLException: No suitable driver found for jdbc::mysql://localhost:3306/asd
我复制了mysql连接器。将jar文件放入jre/lib/ext文件夹。 提前准备好
# 1 楼答案
传递给DriverManager的连接字符串是URL。格式很重要,您的问题是由于
jdbc
和mysql
之间有一个额外的冒号(通过在我自己的系统上测试验证)将
jdbc::mysql:
替换为jdbc:mysql: