Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Willena sqlite jdbc无法打开SqlCipher数据库_Java_Sqlite_Encryption_Sqlcipher - Fatal编程技术网

Java Willena sqlite jdbc无法打开SqlCipher数据库

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

我试图弄清楚如何在非android java中加密sqlite数据库

这看起来并不是非常直截了当,但我确实能够创建一个加密数据库,但我根本不知道如何使用它访问SQLCipher 4加密数据库

这是我的密码

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时,它不允许我访问


我哪里出错了?

好的,所以我最终找到了存储库的创建者。他很容易就解决了,而且回答得很快

以下是解决方案: 以下是一些可以测试的东西:

  • 使用3.31.1版
  • 尝试使用“jdbc:sqlite:file:C:\Users\User1\Desktop\test.db?cipher=sqlcipher&key=password123”作为URI进行数据库连接(注意添加的“file:”)
  • 尝试添加此处可用的SQLCipher的旧参数()。URI将变成这样:“cipher=sqlcipher&key=password123&legacy=4”

  • 这对我来说很有效。我建议其他人使用它,如果他们对一种简单的方法感兴趣,可以像在android项目中一样使用sqlcipher版本4。

    谢谢,它很有效♥