从 netbeans 运行应用程序和运行 jar 有什么区别?



我有一个从Netbeans 7.1运行的java应用程序,但是如果我使用构建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 Version 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)

是什么原因导致的?

我有同样的问题与DriverManager。getConnection调用只是无限期挂起。

解决这个问题的方法是回到Java 6 Update 25。更新29似乎引入了一个JDBC连接SQL Server的错误。我认为更新27(或更早)仍然工作良好

也许您在运行jar文件时没有将CLASSPATH设置为包含SQL Server驱动程序,而Netbeans可能已经为您包含了它。

相关内容

  • 没有找到相关文章

最新更新