1
から鍵ペアを取得し、私はバイトでデータベースに鍵ペアを保存し、データベースへの鍵ペアを保存します。sqliteの日食は、データベース
byte[] pubkey = pair.getPublic().getEncoded();
byte[] privkey = pair.getPrivate().getEncoded();
String sql = "INSERT INTO certs(name, pubkey, privkey) VALUES(?,?,?)";
try (Connection conn = connect();
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, name);
pstmt.setBytes(2, pubkey);
pstmt.setBytes(3, privkey);
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
これは動作します。しかし、私はデータベースからキーを取得したいときはありません。
public static byte[] getPubKey(String name){
String sql = "SELECT pubkey FROM certs WHERE name = ?";
byte[] result = null;
try (Connection conn = connect();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)){
result = rs.getBytes(1);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return result;
}
それを返します: ResultSetが、私はこの問題を解決するにはどうすればよい ヌル
を閉じましたか?また、どのようにして、キーを通常のキーフォーマットに戻すことができますか?
pubkeyは私のクエリですか? – nolags
いいえ、名前... –
がこのpstmt.setString(1、name)に追加されました。今それは動作します。 – nolags