gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:14:54 35 4
gpt4 key购买 nike

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

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com