JDBC替换:SQLNonTransientConnectionException

时间:2016-12-21 13:20:32

标签: java mysql jdbc

在我的java项目中,我从utf8切换到utf8mb4。我删除了数据库,而不是用utf8mb4创建了一个新数据库。 我还使用https://mathiasbynens.be/notes/mysql-utf8mb4的输入更改了mysql-Configuration:my.ini 改变现在看起来像这样:

[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

我查了一下:

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

character_set_filesystem, binary
character_set_client, utf8
character_set_connection, utf8
character_set_results, utf8
character_set_system, utf8
collation_connection, utf8_general_ci
character_set_database, utf8mb4
character_set_server, utf8mb4
collation_database, utf8mb4_unicode_ci
collation_server, utf8mb4_unicode_ci

我尝试添加 - 但是mysql现在还没有启动 - 所以我删除了它:

character_set_client=utf8mb4
character_set_connection=utf8mb4
character_set_results=utf8mb4

现在我重新启动了数据库。

然后我将新驱动程序加载到项目中并用最新的驱动程序替换旧驱动程序。 ( - > now:mysql-connector-java-6.0.5-bin) 我也改变了我的java代码(因为驱动程序错误告诉我要做): 的Class.forName(" com.mysql.cj.jdbc.Driver&#34);

之后我改变了:

    String databaseUrl = "jdbc:mysql://localhost:3306/myDB?useSSL=false&autoReconnect=true&characterEncoding=utf8mb4";

(because: SQLException: java.sql.SQLException: Unsupported character encoding 'utf8mb4'
Exception in thread "JavaFX Application Thread" java.lang.ExceptionInInitializerError)

为:

    String databaseUrl = "jdbc:mysql://localhost:3306/myDB?useSSL=false&autoReconnect=true";

采用新方法抛出:

    SQLException: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Exception in thread "JavaFX Application Thread" java.lang.ExceptionInInitializerError
    at auxiliary.InputCreater.saveFile(InputCreater.java:100)
    at auxiliary.InputCreater.searchnewfiles(InputCreater.java:54)
    at gui.EingabefensterController$3.handle(EingabefensterController.java:70)
    at gui.EingabefensterController$3.handle(EingabefensterController.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.control.MenuItem.fire(MenuItem.java:462)
    at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1405)
    at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$343(ContextMenuContent.java:1358)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at java.util.concurrent.ArrayBlockingQueue.checkNotNull(ArrayBlockingQueue.java:150)
    at java.util.concurrent.ArrayBlockingQueue.offer(ArrayBlockingQueue.java:325)
    at java.util.AbstractQueue.add(AbstractQueue.java:95)
    at java.util.concurrent.ArrayBlockingQueue.add(ArrayBlockingQueue.java:312)
    at mysql.ConnectionPoolManager.initializeConnectionPool(ConnectionPoolManager.java:49)
    at mysql.ConnectionPoolManager.initialize(ConnectionPoolManager.java:43)
    at mysql.ConnectionPoolManager.<init>(ConnectionPoolManager.java:28)
    at mysql.CrawlerUpdate.<clinit>(CrawlerUpdate.java:18)
    ... 46 more

为什么没有连接?在我完成所有这些更改之前,一切正常。

1 个答案:

答案 0 :(得分:0)

问题在于缺失

&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

我通过改变网址找到了它。