2013-05-29 104 views
3

我的意思是哪些文件,我应该向最终用户正确地执行应用程序发布Java桌面应用程序?如何使用SQLite数据库

我可以在我的开发系统上只使用myapp.jar & myapp.db文件在同一文件夹中运行应用程序。但是,当我试图与朋友分享时,他无法加载数据库..

我是否应该将sqlite.dllsqlite.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;   
} 
+0

是否使用的是SQLite的接口?它包装的SQLite本地库(像Xerial一样)还是使用未打包的库或是纯Java? – Femi

+0

我正在使用Xerial JDBC,它使用Eclipse导出打包到可运行的jar中。我也认为这已经足够了。 – LePhleg

+0

当你尝试在不同的机器上运行时,会出现什么特定的异常? – Femi

回答

2

好我的朋友是个白痴。该应用程序正在运行就像一个魅力上两个不同的机器。

大概他没有把.db文件放在第一个地方,并且单独运行.jar创建了一个空的数据库模式来触发错误消息。

因此,对于任何人在问同样的:

NO有没有必要列入sqlite.exesqlite.dll同时发布使用SQLite数据库桌面Java应用程序。刚收拾JDBC驱动程序与可运行.jar和应用程序执行的罚款。

+0

我也将开发小型桌面Java应用程序,N担心相同,所以当在应用程序中使用sqlLite时,有什么事情我们应该关注客户端PC吗?提供链接如何pakging应用程序? – HybrisFreelance

相关问题