gpt4 book ai didi

java - 将 JDBC 连接到 IP 地址

转载 作者:太空宇宙 更新时间:2023-11-03 11:27:32 27 4
gpt4 key购买 nike

<分区>

我在使用 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 字符串。感谢您的帮助。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com