我在使用 JDBC 连接到外部 IP 地址时遇到问题。当我执行以下代码时,出现此错误 No suitable driver found for jdbc:mysql://52.206.157.109:3306/U054Jk
代码:
package util;
import java.sql.*;
public class db {
private static String server = "52.206.157.109";
private static String dbName = "U054Jk";
private static String userName = "secret";
private static String password = "secret";
private static Connection getCon() throws SQLException {
String host = "jdbc:mysql://" + server + ":3306/" + dbName;
Connection conn = DriverManager.getConnection(
host,
userName,
password
);
return conn;
}
public static ResultSet ExecQuery(String query) throws SQLException {
//Get the connection
Connection conn = getCon();
//Create the statement
Statement stmt = conn.createStatement();
//Execute the statement
ResultSet rs = stmt.executeQuery(query);
//Return ResultSet
return rs;
}
}
我可以使用凭据很好地连接我的 SQL 客户端,但不能完全弄清楚我需要的 URL 的 JDBC 字符串。感谢您的帮助。
我是一名优秀的程序员,十分优秀!