W/System.err: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. W/System.err: at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) W/System.err: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918) at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2405) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2326) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46) at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417) W/System.err: at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344) at java.sql.DriverManager.getConnection(DriverManager.java:569) at java.sql.DriverManager.getConnection(DriverManager.java:219) at com.example.jdbc.DbOpenHelper.getConnection(DbOpenHelper.java:33) at com.example.jdbc.MainActivity.insert(MainActivity.java:38) at com.example.jdbc.MainActivity.insert(MainActivity.java:30) at java.lang.reflect.Method.invoke(Native Method) at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) at android.view.View.performClick(View.java:6642) at android.view.View.performClickInternal(View.java:6619) W/System.err: at android.view.View.access$3100(View.java:790) at android.view.View$PerformClick.run(View.java:26187) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:224) at android.app.ActivityThread.main(ActivityThread.java:7056) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876) W/System.err: Caused by: com.mysql.jdbc.exceptions.jdbc4.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 java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127) W/System.err: at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502) at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2344) ... 26 more Caused by: java.net.SocketException: socket failed: EACCES (Permission denied) W/System.err: at java.net.Socket.createImpl(Socket.java:492) at java.net.Socket.<init>(Socket.java:446) at java.net.Socket.<init>(Socket.java:250) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306) ... 28 more I/Choreographer: Skipped 253 frames! The application may be doing too much work on its main thread. I/OpenGLRenderer: Davey! duration=4234ms; Flags=0, IntendedVsync=168849755662264, Vsync=168853972328762, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=168853981852773, AnimationStart=168853982042929, PerformTraversalsStart=168853983408814, DrawStart=168853984611054, SyncQueued=168853987768866, SyncStart=168853987883554, IssueDrawCommandsStart=168853988002304, SwapBuffers=168853989519283, FrameCompleted=168853990608919, DequeueBufferDuration=313000, QueueBufferDuration=504000, I/om.example.jdb: Compiler allocated 4MB to compile void android.view.ViewRootImpl.performTraversals()
使用Navicat for mysql 连接没有问题,但是一用项目连接就出现上面错误,造成这个错误的主要原因是安装的是mysql8.0版本,而项目使用的驱动包是5.1版本,将项目驱动版本改成8.0.11成功解决了此问题。
转载自:https://blog.csdn.net/zht741322694/article/details/82464024