我知道这可能很简单,但我无法弄清楚......
我试图将我的一个程序转换为可运行的jar,并使用JDBC执行一些SQL。当我导出项目时,我选择"将所有必需的库提取到runnable jar",我在构建路径上有JDBC。
这是我的代码的一部分,我被挂断了......
String serverURL = ****
String user = ****
String pass = ****
try {
conn = DriverManager.getConnection(serverURL, user, pass);
} catch (SQLException e) {
//print stacktrack to a dialogbox
}
ResultSet rs = null;
try {
rs = conn.createStatement().executeQuery("SELECT * FROM myDB");
} catch (SQLException e) {
//print stacktrack to a dialogbox
}
所以程序在Eclipse中运行良好但是当我将它作为一个可运行的jar运行时,执行似乎在executeQuery行停止。我已经完成了一些JDialogs,看看问题可能在哪里,看起来conn已经建立(或者至少它不是空的)。由于conn不为null,我认为这意味着JDBC正常工作。奇怪的是,就我所知,没有例外,程序只是在executeQuery行停止。任何想法为什么会这样?
编辑:问题发生前的堆栈跟踪
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:64)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
sun.awt.windows.WToolkit.eventLoop(Native Method)
sun.awt.windows.WToolkit.run(WToolkit.java:306)
java.lang.Thread.run(Thread.java:745)
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:502)
java.lang.ref.Reference.tryHandlePending(Reference.java:191)
java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:502)
sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:295)
java.lang.Thread.run(Thread.java:745)
java.lang.Thread.dumpThreads(Native Method)
java.lang.Thread.getAllStackTraces(Thread.java:1607)
HandMapper.loadRecorded(HandMapper.java:161)
HandMapper.load(HandMapper.java:88)
HandMapper.main(HandMapper.java:255)
sun.awt.windows.WComponentPeer._dispose(Native Method)
sun.awt.windows.WComponentPeer.disposeImpl(WComponentPeer.java:638)
sun.awt.windows.WWindowPeer.disposeImpl(WWindowPeer.java:117)
sun.awt.windows.WObjectPeer.dispose(WObjectPeer.java:88)
java.awt.Component.removeNotify(Component.java:7042)
java.awt.Container.removeNotify(Container.java:2820)
java.awt.Window.removeNotify(Window.java:782)
java.awt.Frame.removeNotify(Frame.java:1041)
java.awt.Window$1DisposeAction.run(Window.java:1190)
java.awt.Window.doDispose(Window.java:1206)
java.awt.Window.dispose(Window.java:1147)
javax.swing.SwingUtilities$SharedOwnerFrame.dispose(SwingUtilities.java:1814)
javax.swing.SwingUtilities$SharedOwnerFrame.windowClosed(SwingUtilities.java:1792)
java.awt.AWTEventMulticaster.windowClosed(AWTEventMulticaster.java:359)
java.awt.Window.processWindowEvent(Window.java:2057)
javax.swing.JDialog.processWindowEvent(JDialog.java:683)
java.awt.Window.processEvent(Window.java:2013)
java.awt.Component.dispatchEventImpl(Component.java:4889)
java.awt.Container.dispatchEventImpl(Container.java:2294)
java.awt.Window.dispatchEventImpl(Window.java:2746)
java.awt.Component.dispatchEvent(Component.java:4711)
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
java.awt.EventQueue.access$500(EventQueue.java:97)
java.awt.EventQueue$3.run(EventQueue.java:709)
java.awt.EventQueue$3.run(EventQueue.java:703)
java.security.AccessController.doPrivileged(Native Method)
java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
java.awt.EventQueue$4.run(EventQueue.java:731)
java.awt.EventQueue$4.run(EventQueue.java:729)
java.security.AccessController.doPrivileged(Native Method)
java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
sun.java2d.Disposer.run(Disposer.java:148)
java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:0)
我建议Maven打包你的依赖项和你的应用程序
良好的网站访问https://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/
一个例子:
<project>
[...]
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
</plugins>
[...]
</build>
</project>