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

标签 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
   // ...
}

感谢您的帮助!

最佳答案

关于java - 打开 SQLite 数据库连接的路径中的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11761052/

相关文章:

java - 需要输入两次 'N'才能显示相关信息

Java 节点交换

database - 如何防止事务违反 Datomic 中的应用程序不变量

php - 对存储此表单中的数据感到困惑

android - sqlite更新一个元组

java - 通过 Maven 导入的类出现 NoClassDef 错误

java - Gridbaglayout、Insets或anchor不会生效

database - mongodb 支持多少个开放的变更流?

java - 从 JAVA 中的游标获取 SQL 命令(android)

带有 SQLite 数据库的 Android Spinner