Eclipse:使用SQLite数据库导出JAR

时间:2015-12-04 15:05:11

标签: java eclipse sqlite jar

我知道这里有一些关于这个主题的问题,但它们似乎对我没有帮助。

我的Eclipse项目中有一个SQLite数据库(Sanus是我项目的名称):

Eclipse Poroject Eclipse

当我在Eclipse中导出到JAR并运行JAR时,应用程序不再与数据库通信了。我不知道路径是不同的还是什么。

如果我拉链并解压缩JAR,我会看到:

enter image description here

这是我用来调用数据库和检索数据的方法:

    public static String Login(String un){
        Statement statement = null;
        try {
          Class.forName("org.sqlite.JDBC");
          connection = DriverManager.getConnection("jdbc:sqlite:PatientRegistry.sqlite");
          connection.setAutoCommit(false);
          String password=null;
          statement = connection.createStatement();
          ResultSet rs = statement.executeQuery( "SELECT password, fullName FROM users WHERE username = '"+un+"';" );
          while ( rs.next() ) {
             password = rs.getString("password");
             MainClass.userFullName = rs.getString("fullName");
          }
          rs.close();
          statement.close();
          connection.close();
          return password;
        } catch ( Exception e ) {
          System.out.println("There's a problem with the database.");
          return null;
        }
    }

0 个答案:

没有答案
相关问题