Created
May 2, 2018 11:29
-
-
Save mluukkai/0a397c4c0af40133df046f23b10086e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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