0

我正在尝试连接到 SQLite 数据库(在 Windows 8 上使用 Eclipse)。只要路径名不包含任何特殊字符(如“é”),一切正常。我试图将它转换为 UTF-8(因为我在http://www.sqlite.org/c3ref/open.html上读到它应该是),但它没有用。我收到“内存不足”异常 (SQLException),这意味着找不到数据库文件。

这是我所做的代码摘要:

public static String DB_PATH = "jdbc:sqlite:" + System.getProperty("user.home") + "<Rest of the path><databasename>.sqlite";

public static void main(String[] args) throws ClassNotFoundException
{
  // load the sqlite-JDBC driver using the current class loader
  Class.forName("org.sqlite.JDBC");

 Connection connection = null;
 try
 {
   // create a database connection
   connection = DriverManager.getConnection(DB_PATH);
   Statement statement = connection.createStatement();
   statement.setQueryTimeout(30);  // set timeout to 30 sec.

   // work with the database ...
   }
 }
 catch(SQLException e)
 {
   // if the error message is "out of memory", 
   // it probably means no database file is found
   System.err.println(e.getMessage());
 }
 finally
 {
   // try to disconnect
   // ...
}

谢谢你的帮助!

4

1 回答 1

1

使用来自http://www.xerial.org/maven/repository/artifact/org/xerial/sqlite-jdbc/的最新库

于 2012-08-10T14:23:28.810 回答