[英]Embedded Database into Jar File
For the past couple of days I have been trying to get my Derby database to be accessed in my jar file. 在过去的几天中,我一直在尝试通过jar文件访问Derby数据库。 Here is what my connection class looks like:
这是我的连接类的样子:
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
public class DBConnection
{
public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
public static final String JDBC_URL = "jdbc:derby:EmployeeInfo";
public static Connection dbConnector()
{
try
{
Class.forName(DRIVER).newInstance();
Connection conn = DriverManager.getConnection(JDBC_URL);
JOptionPane.showMessageDialog(null, "Connection successfull");
return conn;
}catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
Also, here is a screenshot of what my project explorer looks like: 另外,这是我的项目浏览器的屏幕截图:
Everything works when I am in eclipse, my program runs as expected with my GUI updating the Database. 当我日食时一切正常,程序运行正常,GUI更新数据库。 But the minute I make my program a jar file it says it can't find my database EmployeeInfo (note: Database.jar is the EmployeeInfo database).
但是,当我将程序制作为jar文件的那一刻,它说它找不到我的数据库EmployeeInfo(注意:Database.jar是EmployeeInfo数据库)。 One last thing, when I try the jar file out on a different machine it also states that it cannot find the database.
最后一件事,当我在另一台机器上尝试jar文件时,它也指出找不到数据库。
An explination on why this is going along with any fixes would be great! 解释为什么这样做以及进行任何修复将是很棒的! -Thanks, Aaron :)
-谢谢亚伦:)
Well i eventually found the fix :). 好吧,我最终找到了解决方法:)。 I had to place the embedded derby database files into a folder along with the derby jars, and my jar file that contained my project and everything worked beautifully!
我必须将嵌入式derby数据库文件与derby jar一起放置到一个文件夹中,并且包含我的项目的jar文件和所有文件都能正常工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.