打开SQLite数据库连接的路径中的特殊字符

时间:2012-08-01 14:05:42

标签: java database sqlite classnotfoundexception sqlitejdbc

我正在尝试连接到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
   // ...
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)