2
我做了一个简单的MySQL连接程序,但它不起作用。XAMPP jdbc驱动程序不加载
package main;
import java.sql.*;
public class Main {
static Connection con = null;
static Statement stmt = null;
static ResultSet rs = null;
static String url = "jdbc:mysql://localhost:3306/phpmyadmin";
static String user = "root";
static String password = "(i dont show this ;)";
public static void main(String[] args) {
try {
System.out.println("Connecting database...");
con = DriverManager.getConnection(url, user, password);
System.out.println("Database connected!");
} catch (SQLException e) {
throw new RuntimeException("Cannot connect the database!", e);
} finally {
System.out.println("Closing the connection.");
if (con != null) try { con.close(); } catch (SQLException ignore) {}
}
}
}
我得到这个错误:
Connecting database...
Closing the connection.
Exception in thread "main" java.lang.RuntimeException: Cannot connect the database!
at main.Main.main(Main.java:22)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/phpmyadmin
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at main.Main.main(Main.java:19)
我所做的构建路径,并且我从lib文件夹移动(从连接器)的文件\xampp\mysql\lib
。我也开始tomcat(我没有改变任何配置),它仍然无法正常工作。
OMG * _ *它的作品!万分感谢!!!!!! – Andi
@ user3043098如果它能正常工作,请接受答案作为最佳答案,这样我也可以鼓励提供更有用的答案 – Deepak