Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mluukkai/0a397c4c0af40133df046f23b10086e5 to your computer and use it in GitHub Desktop.
Save mluukkai/0a397c4c0af40133df046f23b10086e5 to your computer and use it in GitHub Desktop.
/**
* Finds data by title name from the database.
*/
public Data findOne(String title, Profile profile) throws SQLException {
if (title == null) {
return null;
}
Consumer<PreparedStatement> statement = (stmnt) -> {
try{
stmnt.setString(1, title);
stmnt.setString(2, profile.getName());
} catch(Exception e){}
};
ResultSet rs = findOneGeneric("SELECT * FROM Data WHERE title = ? AND profile_name = ?", statement);
Data encryptedData = new Data(rs.getString("title"), rs.getString("content"), rs.getString("a"));
return encryptedData;
}
public ResultSet findOneGeneric(String sql, Consumer<PreparedStatement> consumer) throws SQLException {
try (Connection conn = database.getConnection()) {
PreparedStatement stmnt = conn.prepareStatement(sql);
consumer.accept(stmnt);
ResultSet rs = stmnt.executeQuery();
return rs;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment