Help with CRYPT_KEY needed

Help
elnin0
2013-12-05
2014-01-29
  • elnin0

    elnin0 - 2013-12-05

    I'm trying to get a AES encryption key generation by a HSQLDB database to work. The documentation of this feature is very basic and the only code listing for this task i found here: http://www.coderanch.com/t/515884/JDBC/databases/Encrypted-database-HSQL

    Unfortunately this Code is not working i get a java.sql.SQLException: invalid cursor state: identifier cursor not positioned on row in UPDATE, DELETE, SET, or GET statement: ; ResultSet is empty

    here is the code from the coderanche post:

    SOMETHING HEREClass.forName("org.hsqldb.jdbc.JDBCDriver");
    Connection con = DriverManager.getConnection("jdbc:hsqldb:file:some_db", "SA", "");
    Statement stmt = con.createStatement();  
    ResultSet rs = stmt.executeQuery("select CRYPT_KEY('AES', null) from some_table");
    rs.next();
    String key = rs.getString(1);
    
     
  • Lucani

    Lucani - 2013-12-05

    Try this:

            try {
                PreparedStatement stmt = connection.prepareStatement("SELECT CRYPT_KEY('AES', NULL) FROM (VALUES(0))");
                ResultSet rs = stmt.executeQuery();
                rs.next();
                String key = rs.getString(1);
                System.out.println(key);
            } catch (SQLException e) {
                e.printStackTrace();
            }
    
     
  • Fred Toussi

    Fred Toussi - 2014-01-29

    For interactive use (rather than programmatic), you start DatabaseManager and connect to a new mem: database. You then type this:

     CALL CRYPT_KEY('AES', NULL)
    

    The returned value is displayed in the window. If you click on the View menu and select View as Text, you can highlight and copy the result to the clipboard.

     

Log in to post a comment.