我用Eclipse在Windows上创建了一个java程序,它连接到Hostinger上托管的Mysql数据库。我设置了连接,以便能够从外部访问数据库。当我在Windows上运行程序时,我可以毫无错误地访问我的数据库。
然后我将这个程序导出到一个jar文件中,并在我的Raspberry上创建了一个localhost数据库,并尝试了这个程序,它运行得非常完美。现在,当我将数据库更改为访问Hostinger上的数据库时,我在Raspberry上得到了以下错误:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.为什么我在我的覆盆子上会出现这个错误,而不是在窗户上呢?我正在用逗号运行程序:java -jar myprogram.jar
下面是代码:db.properties
# mysql properties
mysql.driver=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://ip_hostinger:3306/database_name
mysql.username=user
mysql.password=pwdDatabase.java
public static MysqlDataSource getMySQLDataSource() throws FileNotFoundException, IOException {
Properties props = new Properties();
InputStream is = null;
MysqlDataSource ds = null;
is = Database.class.getResourceAsStream("db.properties");
props.load(is);
ds = new MysqlConnectionPoolDataSource();
ds.setURL(props.getProperty("mysql.url"));
ds.setUser(props.getProperty("mysql.username"));
ds.setPassword(props.getProperty("mysql.password"));
return ds;
}
public static ArrayList<String> DatabaseSelect() throws IOException, SQLException {
Connection con = null;
Statement stm = null;
ResultSet rs = null;
ArrayList<String> resultSelect = new ArrayList<String>();
try {
con = getMySQLDataSource().getConnection();
stm = con.createStatement();
rs = stm.executeQuery("SELECT * from table");
while (rs.next()) {
String str = rs.getString("str");
resultSelect.add(str);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (con != null) {
con.close();
}
}
return resultSelect;
}发布于 2021-12-14 11:44:41
通过在文件/usr/lib/jvm/java-11-openjdk-armhf/conf/security/java.security中注释这些行来解决问题
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
include jdk.disabled.namedCurveshttps://stackoverflow.com/questions/70275087
复制相似问题