java.sql.SQLException:通过tomcat连接时没有选择数据库异常 [英] java.sql.SQLException: No database selected Exception when connecting via tomcat

查看:22
本文介绍了java.sql.SQLException:通过tomcat连接时没有选择数据库异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下异常:

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

我使用 CentOS 7 和 MariaDB (tomcat8/java8).我已经更改了 maria db 的 my.cnf 中的默认端口,然后 -> 发生了这个异常.我使用hibernate,我已经更改了hibernate.cfg.xml中的端口

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

是否可以通过不同的端口连接到 mysql?而不是 3306 还是不推荐使用?

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

我已经恢复到端口 3306(默认)然后我得到以下异常:

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)

谢谢

推荐答案

已解决

tomcat 重启脚本(服务)是问题所在.可能服务器重新启动不干净并且连接池大小已超出.

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

手动执行shutdown.sh 和startup.sh - 问题已解决".

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

谢谢!

这篇关于java.sql.SQLException:通过tomcat连接时没有选择数据库异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆