我的意思是我应该向最终用户提供哪些文件才能正确执行应用程序?
我可以仅使用同一文件夹中的myapp.jar
&文件在我的开发系统上运行该应用程序。myapp.db
但是当我尝试与朋友分享时,他无法加载数据库..
我应该将sqlite.dll
orsqlite.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;
}