From 505feda055a1f5c59aea53f26680bbbbb0553a0a Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Thu, 20 Jun 2013 18:26:34 +0700 Subject: SQLHelpers.getInt --- src/com/juick/server/SQLHelpers.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/com/juick/server/SQLHelpers.java') diff --git a/src/com/juick/server/SQLHelpers.java b/src/com/juick/server/SQLHelpers.java index dd83a915..7879c244 100644 --- a/src/com/juick/server/SQLHelpers.java +++ b/src/com/juick/server/SQLHelpers.java @@ -16,6 +16,25 @@ import java.util.ArrayList; */ public class SQLHelpers { + public static int getInt(Connection sql, String query, int param, int defvalue) { + int ret = defvalue; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement(query); + stmt.setInt(1, param); + rs = stmt.executeQuery(); + if (rs.first()) { + ret = rs.getInt(1); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return ret; + } + public static ArrayList getArrayInteger(Connection sql, String query, int param) { ArrayList ret = new ArrayList(); -- cgit v1.2.3