我已经使用hibernate创建了一个应用程序...当我通过Netbeans运行它时,它可以正常使用数据库。但是当我构建应用程序(使用清理和构建工具)时,它不适用于数据库。
错误:
WARNING: SQL Error: 40000, SQLState: 08001
May 21, 2010 4:25:11 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: java.net.ConnectException : Error connecting to server localhost on port
1527 with message Connection refused: connect.
Exception in thread "AWT-EventQueue-0"
org.hibernate.exception.JDBCConnectionException: **Cannot open connection**
at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnectio n(ConnectionManager.java:426)
at org.hibernate.jdbc.ConnectionManager.getConnection (ConnectionManager.java:144)
at org.hibernate.jdbc.AbstractBatcher.prepareQuerySta tement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement( Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:67 3)
at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:222 0)
at org.hibernate.loader.Loader.listIgnoreQueryCache(L oader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoa der.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(Que ryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performLis t(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:7 9)
at ajmalispatientdatamanager.StartPage.searchMethod(S tartPage.java:852)
at ajmalispatientdatamanager.StartPage.SearchBtnActio nPerformed(StartPage.java:599)
at ajmalispatientdatamanager.StartPage.access$900(Sta rtPage.java:33)
at ajmalispatientdatamanager.StartPage$8.actionPerfor med(StartPage.java:382)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.sql.SQLNonTransientConnectionException: java.net.ConnectException :
Error connecting to server localhost on port 1527 with message Connection refused:
connect.
at org.apache.derby.client.am.SQLExceptionFactory40.g etSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLExce ption(Unknown Source)
at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionPr
ovider.getConnection(DriverManagerConnectionProvid er.java:110)
at org.hibernate.jdbc.ConnectionManager.openConnectio n(ConnectionManager.java:423)
... 42 more
Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectException :
Error connecting to server localhost on port 1527 with message Connection refused:
connect.
at org.apache.derby.client.net.NetAgent.<init>(Unknow n Source)
at org.apache.derby.client.net.NetConnection.newAgent _(Unknown Source)
at org.apache.derby.client.am.Connection.<init>(Unkno wn Source)
at org.apache.derby.client.net.NetConnection.<init>(U nknown Source)
at org.apache.derby.client.net.NetConnection40.<init> (Unknown Source)
at org.apache.derby.client.net.ClientJDBCObjectFactor yImpl40.newNetConnection(Unknown
Source)
... 47 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at javax.net.DefaultSocketFactory.createSocket(Unknow n Source)
at org.apache.derby.client.net.OpenSocketAction.run(U nknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 53 more
请帮助我。 请帮助我。
答案 0 :(得分:0)
这与jar没有任何关系 - 相反,它是数据库连接权限问题。
1)hibernate配置中的地址或帐户信息(与jar一起打包)与工作的netbeans代码使用的地址或帐户信息不正确或不完整....您是否在jar中使用相同的配置文件netbeans的?
或者
2)。您正在从未授权连接到数据库的计算机上运行jar - 例如,您可能是从非root授权IP地址以root身份连接....您是否在使用的同一台计算机上运行jar netbeans on?