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

查看:190
本文介绍了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.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天全站免登陆