java.sql.SQLException: No database selected Exception when connecting via tomcat

不想你离开。 提交于 2019-12-25 16:25:41

问题


I get following Exception:

Caused by: java.sql.SQLException: No database selected
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2030)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
        ... 52 more

I use CentOS 7 with MariaDB (tomcat8 / java8). I've changed the default Port in the my.cnf of maria db, then -> this exception occured. I use hibernate and i have already changed the port in the hibernate.cfg.xml

Is it possible to connect to mysql via a different port? instead of 3306 or is this not recommended?

I've reverted to port 3306 (default) then i get following exception:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 17,287 milliseconds ago.  The last packet sent successfully to the server was 1 milliseconds ago.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:408)

Thank you


回答1:


SOLVED

the tomcat restart script (service) was the problem. may the restart of the server was not clean and the connection pool size exeeded.

Manually executed the shutdown.sh and the startup.sh - problem "solved".

Thank you!



来源:https://stackoverflow.com/questions/29129984/java-sql-sqlexception-no-database-selected-exception-when-connecting-via-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!