java.sql.SQLNonTransientConnectionException

2.1k Views Asked by At

Excuse me I'm beginner on java programmer and I try to coding java for show data in JTable from MariaDB on Ubuntu OS.

But I got some error code like this:

"java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=xxx.xx.xxx.xx)(port=3306)(type=master) : Connection timed out: connect".

Can someone help me or guide me to solve this problem please. Thank you so much for your all answers.

public void ConU() {

    try {

        Class.forName("org.mariadb.jdbc.Driver");
        ConDB = DriverManager.getConnection("jdbc:mariadb://xxx.xx.xxx.xx:3306/user", "root", "root");
        System.out.println("Connected database successfully...");
        /*---------------------------------------------------------------------*/
        //Class.forName("com.mysql.jdbc.Driver");
        System.out.println("Creating table in given database...");
        stm = ConDB.createStatement();
        String sql = "CREATE TABLE User3kwan "
                + "(id INTEGER AUTO_INCREMENT, "
                + " fname VARCHAR(50), "
                + " lname VARCHAR(50), "
                + " nname VARCHAR(10), "
                + " phone VARCHAR(30), "
                + " PRIMARY KEY ( id ))";
        stm.executeUpdate(sql);
        System.out.println("Created table in given database...");

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (stm != null) {
                ConDB.close();
            }
        } catch (SQLException ex) {

        }

        try {
            if (ConDB != null) {
                ConDB.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}
0

There are 0 best solutions below