MySQL连接在Android Studio MySQL版本8.0.13中不起作用

我正在制作一个程序,但我的MySQL不工作,我不知道为什么 . 我使用的是MySQL Server 8.0.13和Connector / J 8.0.13 . 我从视频中复制了它,但视频使用了其他版本的MySQL . [视频]:https://www.youtube.com/watch?v=bu5Y3uZ6LLM我不知道它的JDBC连接是错误的还是我使用了错误的用户名 . 它只是没有多大意义,因为它适用于他的视频 .

String msg = "";
    //JDBC driver name and database URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://" +
            DbStrings.DATABASE_URL + "/" +
            DbStrings.DATABASE_NAME;
    @Override
    protected void onPreExecute() {
        ProgressTextView.setText("Connecting to Database...");
    }

    @Override
    protected String doInBackground(String... params) {
        Connection conn = null;
        Statement stmt = null;

        try {
            Class.forName(JDBC_DRIVER);
            conn = DriverManager.getConnection(DB_URL, DbStrings.USERNAME, DbStrings.PASSWORD);

            stmt = conn.createStatement();
            String sql = "SELECT * FROM zimmerstamm";
            ResultSet rs = stmt.executeQuery(sql);

            while (rs.next()) {
                String Bemerkung = rs.getString("Bemerkung");
                Double Zimmer = rs.getDouble("Zimmer");

                fruitsMap.put(Bemerkung, Zimmer);
            }
            msg = "Process complete";

            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException connError)

我得到这个错误:

W/System.err: 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.
        at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
W/System.err:     at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
        at java.sql.DriverManager.getConnection(DriverManager.java:569)
        at java.sql.DriverManager.getConnection(DriverManager.java:219)
W/System.err:     at com.example.patrick.putzapp.feature.MainActivity$GetData.doInBackground(MainActivity.java:71)
        at com.example.patrick.putzapp.feature.MainActivity$GetData.doInBackground(MainActivity.java:51)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err:     at java.lang.Thread.run(Thread.java:764)
    Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
W/System.err: The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
W/System.err:     at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
W/System.err:     at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
W/System.err:     at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91)
W/System.err:     at com.mysql.cj.NativeSession.connect(NativeSession.java:152)
        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
        ... 13 more
W/System.err: Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 3306) from /:: (port 60052): connect failed: ECONNREFUSED (Connection refused)
        at libcore.io.IoBridge.connect(IoBridge.java:137)
        at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:137)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
W/System.err:     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
W/System.err:     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
        at java.net.Socket.connect(Socket.java:621)
        at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
        at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
        ... 16 more
    Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
W/System.err:     at libcore.io.Linux.connect(Native Method)
        at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:118)
        at libcore.io.IoBridge.connectErrno(IoBridge.java:151)
        at libcore.io.IoBridge.connect(IoBridge.java:129)
        ... 24 more

回答(0)