已有101人关注
搭建Hibernate框架后运行主窗体,连接失败
发表在Java图书答疑 2020-07-03 悬赏:10 学分 《Java项目开发实战入门》第2章 通讯录系统 96页-98页
是否精华
版块置顶:

主窗体中主方法加System.out.println(DaoFactory.getDao().selectAllUser().size());按照视频教的运行,但是连接数据库失败,数据库IP和密码都输入的正确,控制台显示的是:

七月 03, 2020 8:55:52 上午 org.hibernate.util.JDBCExceptionReporter logExceptions

警告: SQL Error: 0, SQLState: 08001

七月 03, 2020 8:55:52 上午 org.hibernate.util.JDBCExceptionReporter logExceptions

严重: Could not create connection to database server.

Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connection

at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)

at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)

at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)

at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)

at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)

at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1560)

at org.hibernate.loader.Loader.doQuery(Loader.java:661)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)

at org.hibernate.loader.Loader.doList(Loader.java:2144)

at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)

at org.hibernate.loader.Loader.list(Loader.java:2023)

at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)

at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)

at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)

at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)

at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)

at com.mr.contact.dao.DAOimpl.selectAllUser(DAOimpl.java:194)

at frame.MainFrame.main(MainFrame.java:25)

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)

at com.mysql.jdbc.Util.getInstance(Util.java:383)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:958)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2326)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2079)

at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)

at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)

at java.sql.DriverManager.getConnection(Unknown Source)

at java.sql.DriverManager.getConnection(Unknown Source)

at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)

at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)

... 15 more

Caused by: java.lang.NullPointerException

at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:2999)

at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1885)

at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1814)

at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1207)

at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2249)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2280)

... 29 more

麻烦哪位老师给看下怎么回事,谢谢

2020-07-03 09:21:39编辑
分享到:
精彩评论 2
根号申
学分:4736 LV12
TA的每日心情
2021-07-16 23:48:46
2020-07-03
沙发

你连接的目标不存在数据库服务

game99258
学分:2266 LV10
2022-08-19
板凳

网址对吗?

首页上一页 1 下一页尾页 2 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照