gpt4 book ai didi

java - HTTP 状态 500 - org.hibernate.exception.SQLGrammarException : Cannot open connection

转载 作者:行者123 更新时间:2023-11-29 19:30:39 25 4
gpt4 key购买 nike

当我尝试通过 hibernate 连接时,出现上述错误。但是当我通过 jdbc 驱动程序连接时,一切工作正常。因此连接字符串不是问题。请指导我解决此错误。是否缺少任何 jar 文件,请告诉我

type Exception report

message org.hibernate.exception.SQLGrammarException: Cannot open connection

description The server encountered an internal error that prevented it from fulfilling this request.

exception
java.lang.RuntimeException: org.hibernate.exception.SQLGrammarException: Cannot open connection
model.LoginBean.authorized(LoginBean.java:41)
controller.ShopServlet.processLoginPost(ShopServlet.java:68)
controller.ShopServlet.doPost(ShopServlet.java:55)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
org.hibernate.exception.SQLGrammarException: Cannot open connection
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:424)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
org.hibernate.loader.Loader.doQuery(Loader.java:661)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
org.hibernate.loader.Loader.doList(Loader.java:2211)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
org.hibernate.loader.Loader.list(Loader.java:2090)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
model.LoginBean.authorized(LoginBean.java:31)
controller.ShopServlet.processLoginPost(ShopServlet.java:68)
controller.ShopServlet.doPost(ShopServlet.java:55)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
java.sql.SQLException: Syntax error or access violation message from server: "Unknown database 'root'"
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2001)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1907)
com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:2524)
com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:818)
com.mysql.jdbc.Connection.createNewIO(Connection.java:1808)
com.mysql.jdbc.Connection.<init>(Connection.java:452)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:421)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
org.hibernate.loader.Loader.doQuery(Loader.java:661)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
org.hibernate.loader.Loader.doList(Loader.java:2211)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
org.hibernate.loader.Loader.list(Loader.java:2090)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
model.LoginBean.authorized(LoginBean.java:31)
controller.ShopServlet.processLoginPost(ShopServlet.java:68)
controller.ShopServlet.doPost(ShopServlet.java:55)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

最佳答案

此错误可能是由于数据库名称不正确造成的。您能否检查一下您是否还指定了数据库名称?

try {
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e) {
throw new Exception("No database");
}
String connectionURL = "jdbc:mysql://localhost:3306/dbname";
con = DriverManager.getConnection(connectionURL, "root", "password");

关于java - HTTP 状态 500 - org.hibernate.exception.SQLGrammarException : Cannot open connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41793234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com