I'm working on a program for fun but the MySQL
driver and connection code isn't working properly I got the error
Error: no suitable driver found
MeanWhile my code contains the Class.forName("com.mysql.jdbc.Driver");
line. I have the newest MySQL
jar file in my class path. any suggestions I could try to fix the problem
private void connect() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(URL,user,pass);
stmt = con.createStatement();
} catch (Exception e) {
error = true;
e.printStackTrace();
}
}
您的问题是URL
的语法不正确,您在mysql
之后忘记了冒号,应该为jdbc:mysql://...
有关mysql
情况下URL
语法的更多详细信息,请参考此网站页
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.