问题
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