我有一个java应用程序,当从Netbeans 7.1运行时效果很好但是如果我使用构建jar它会崩溃。
我一直在调查这个问题,我注意到应用程序在调用DriverManager.getConnection()时仍然存在。
我正在做类似的事情:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:2304;user=username;password=12345;database=databasename");
我也试过jtds,但结果相同。
我在Windows 7家庭高级版上运行 SQL Server 2008(localhost) Netbeans 7.1(从Netbeans运行时应用程序运行正常) Java版本1.6
线程转储
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Unknown Source)
at joomlasyncrnzr.JoomlaSyncrnzrApp.getCon(JoomlaSyncrnzrApp.java:314)
at joomlasyncrnzr.JoomlaSyncrnzrApp.taxas(JoomlaSyncrnzrApp.java:604)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(Ap
licationAction.java:662)
at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicatinAction.java:698)
at javax.swing.AbstractButton.fireActionPerformed(Unknown 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.mouseReleased(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(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown 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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
可能导致这种情况的原因是什么?
答案 0 :(得分:1)
我遇到的问题是DriverManager.getConnection调用只是无限期挂起。
为我解决问题的原因是回到Java 6 Update 25.更新29似乎引入了与SQL Server的JDBC连接的错误。我认为更新27(或更早)仍然可以正常工作。
答案 1 :(得分:0)
也许你没有在运行jar文件时将CLASSPATH设置为包含SQL Server驱动程序,而Netbeans可能已经为你包含了它。