jdbc远程访问mysql数据库

bejyjqdl  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(272)

我一直在使用wamp和mysql为我的java项目使用本地数据库,一切正常。最近我在windows服务器上安装了awsec2vm。安装了wamp和mysql。
我设法让远程访问apache和mysql,因此我能够访问phpmyadmin、db,并通过浏览器使用其地址从外部计算机与之交互:http://15.188.65.36/phpmyadmin/
但是,当我改变了我以前(为我的本地wamp)的工作很好

public static ResultSet execute(String requete) {
        Connection connexion;
        Statement stmt = null;
        ResultSet res = null;
        try {
            connexion = DriverManager.getConnection ("jdbc:mysql://localhost:3306/dbname","user","*********");
            stmt = connexion.createStatement();
            if(stmt.execute(requete)) {
                res = stmt.getResultSet();
            }
        } catch (SQLException e) {

            System.out.println(e.getMessage());
        }
        return res;
    }

对于

public static ResultSet execute(String requete) {
        Connection connexion;
        Statement stmt = null;
        ResultSet res = null;
        try {
            connexion = DriverManager.getConnection ("jdbc:mysql://15.188.65.36:3306/dbname","user","*********");
            stmt = connexion.createStatement();
            if(stmt.execute(requete)) {
                res = stmt.getResultSet();
            }
        } catch (SQLException e) {

            System.out.println(e.getMessage());
        }
        return res;
    }

它不再工作了,似乎无法连接,我收到以下错误:

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.

谢谢你的帮助

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题