Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **
- * Query a command to get its value in an async task
- *
- * @param statement : The statement
- * @param row : The row
- */
- public void queryRowAsync(String statement, String row, SqlCallback<List<Object>> callback) {
- if (!checkConnection()) throw new IllegalStateException("Cannot connect into the database!");
- Bukkit.getScheduler().runTaskAsynchronously(getOwningPlugin(), () -> {
- PreparedStatement ps = null;
- ResultSet rs;
- List<Object> values = new ArrayList<>();
- try {
- ps = connection.prepareStatement(statement);
- rs = ps.executeQuery();
- while (rs.next()) {
- values.add(rs.getObject(row));
- }
- callback.onSuccess(values);
- } catch (SQLException ex) {
- try {
- if (ps != null) {
- ps.close();
- }
- if (connection != null) {
- connection.close();
- }
- callback.onError(ex);
- } catch (SQLException ex2) {
- callback.onError(ex2);
- }
- }
- finally {
- try {
- if (ps != null) {
- ps.close();
- }
- if (connection != null) {
- connection.close();
- }
- }
- catch (SQLException ex2) {
- callback.onError(ex2);
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement