首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Raspbian /Linux 11上执行jar时Java通信链路失败(斗牛眼)

在Raspbian /Linux 11上执行jar时Java通信链路失败(斗牛眼)
EN

Stack Overflow用户
提问于 2021-12-08 12:33:34
回答 1查看 97关注 0票数 0

我用Eclipse在Windows上创建了一个java程序,它连接到Hostinger上托管的Mysql数据库。我设置了连接,以便能够从外部访问数据库。当我在Windows上运行程序时,我可以毫无错误地访问我的数据库。

然后我将这个程序导出到一个jar文件中,并在我的Raspberry上创建了一个localhost数据库,并尝试了这个程序,它运行得非常完美。现在,当我将数据库更改为访问Hostinger上的数据库时,我在Raspberry上得到了以下错误:

代码语言:javascript
复制
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

代码语言:javascript
复制
# mysql properties
mysql.driver=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://ip_hostinger:3306/database_name
mysql.username=user
mysql.password=pwd

Database.java

代码语言:javascript
复制
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;
    }
EN

回答 1

Stack Overflow用户

发布于 2021-12-14 11:44:41

通过在文件/usr/lib/jvm/java-11-openjdk-armhf/conf/security/java.security中注释这些行来解决问题

代码语言:javascript
复制
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
     DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
     include jdk.disabled.namedCurves
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70275087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档