我的意思是哪些文件,我应该向最终用户正确地执行应用程序发布Java桌面应用程序?如何使用SQLite数据库
我可以在我的开发系统上只使用myapp.jar
& myapp.db
文件在同一文件夹中运行应用程序。但是,当我试图与朋友分享时,他无法加载数据库..
我是否应该将sqlite.dll
或sqlite.exe
文件也包含到应用程序目录中?
注:数据库用于检索和运行过程中存储的数据。
编辑: 它是一个SWING应用程序,所以当数据库或其模式丢失时出现弹出错误。 下面的代码: “数据库中不存在”
public boolean DBExists(Connection con,String dbName) { Statement stmt = null; ResultSet res = null; try { String sql = "SELECT name FROM sqlite_master WHERE TYPE='table';"; stmt = con.createStatement(); res = stmt.executeQuery(sql); } catch(SQLException e) { System.out.println("Error creating or running SELECT statement: " + e.toString()); } try { if (res.next()) { System.out.println("Database checked!"); return true; } else { System.out.println("Database doesnt exist!"); return false; } } catch (SQLException e) { System.out.println("Error processing results: " + e.toString()); } System.out.println("Problem while checking database availability."); return false; }
的消息被触发。
编辑#2:
这也是它调用DBExist(检查连接方法):
public Connection DBConnect() {
//STEP 1: Setup the Driver
try
{
//Load the JDBC driver class dynamically.
Driver d = (Driver)Class.forName(DRIVER).newInstance();
DriverManager.registerDriver(d);
System.out.println("Driver loaded successfuly!");
}
catch(Exception e)
{
System.out.println("Error loading database driver: " + e.toString());
return null;
}
//STEP 2: Create connection to database using database URL
Connection con;
try
{
//FIXME: Load database filename via external config.
con = DriverManager.getConnection(URL);
System.out.println("Database connection successfull!");
if (!DBExists(con,DB_NAME)) {
JOptionPane.showMessageDialog(null,
"Database file was not found!",
"Database Fatal Error",
JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
catch(SQLException e)
{
System.out.println("Error creating connection: " + e.toString());
return null;
}
return con;
}
是否使用的是SQLite的接口?它包装的SQLite本地库(像Xerial一样)还是使用未打包的库或是纯Java? – Femi
我正在使用Xerial JDBC,它使用Eclipse导出打包到可运行的jar中。我也认为这已经足够了。 – LePhleg
当你尝试在不同的机器上运行时,会出现什么特定的异常? – Femi