Java Willena sqlite jdbc无法打开SqlCipher数据库
我试图弄清楚如何在非android java中加密sqlite数据库 这看起来并不是非常直截了当,但我确实能够创建一个加密数据库,但我根本不知道如何使用它访问SQLCipher 4加密数据库 这是我的密码Java Willena sqlite jdbc无法打开SqlCipher数据库,java,sqlite,encryption,sqlcipher,Java,Sqlite,Encryption,Sqlcipher,我试图弄清楚如何在非android java中加密sqlite数据库 这看起来并不是非常直截了当,但我确实能够创建一个加密数据库,但我根本不知道如何使用它访问SQLCipher 4加密数据库 这是我的密码 String path = "jdbc:sqlite:C:\\Users\\User1\\Desktop\\testServer232.db"; Connection connection = null; try { // creat
String path = "jdbc:sqlite:C:\\Users\\User1\\Desktop\\testServer232.db";
Connection connection = null;
try
{
// create a database connection
connection = DriverManager.getConnection(path+"?cipher=sqlcipher&key=a");
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); // set timeout to 30 sec.
statement.executeUpdate("drop table if exists person");
statement.executeUpdate("create table person (id integer, name string)");
statement.executeUpdate("insert into person values(3, 'leo1')");
statement.executeUpdate("insert into person values(4, 'yui1')");
ResultSet rs = statement.executeQuery("select * from person");
while(rs.next())
{
// read the result set
System.out.println("name = " + rs.getString("name"));
System.out.println("id = " + rs.getInt("id"));
}
}
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
{
if(connection != null)
connection.close();
}
catch(SQLException e)
{
// connection close failed.
System.err.println(e.getMessage());
}
}
这段代码确实有效,但我认为它不会生成SqlCipher 4加密数据库。当我尝试使用DB browser for Sqlite打开它时,当我输入密码=a时,它不允许我访问
我哪里出错了?好的,所以我最终找到了存储库的创建者。他很容易就解决了,而且回答得很快 以下是解决方案: 以下是一些可以测试的东西:
这对我来说很有效。我建议其他人使用它,如果他们对一种简单的方法感兴趣,可以像在android项目中一样使用sqlcipher版本4。谢谢,它很有效♥