简体   繁体   English

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

[英]Special character in path to open SQLite database connection

I am trying to get a connection to a SQLite database (using Eclipse on Windows 8). 我正在尝试连接到SQLite数据库(在Windows 8上使用Eclipse)。 Everything workes fine as long as the path name doesn't contain any special characters (like "é"). 只要路径名不包含任何特殊字符(例如“é”),一切都可以正常工作。 I tried to convert it to UTF-8 (because I read on http://www.sqlite.org/c3ref/open.html that it should be), but it didn't work. 我尝试将其转换为UTF-8(因为我在http://www.sqlite.org/c3ref/open.html上读到了应该的文字),但是没有用。 I get an "out of memory" exception (SQLException) what means that no database file was found. 我收到“内存不足”异常(SQLException),这意味着未找到数据库文件。

This is the code summary of what I did: 这是我所做的代码摘要:

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

Thanks for your help! 谢谢你的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM