diff options
author | Ugnich Anton | 2013-06-21 00:48:01 +0700 |
---|---|---|
committer | Ugnich Anton | 2013-06-21 00:48:01 +0700 |
commit | 1afa0e255d694840c77c19c1effed6c0d0a92f1f (patch) | |
tree | ace81103e2bd93349e7598e514e02cb0c2ead364 /src/com/juick/server/SQLHelpers.java | |
parent | 781648961858a5180098954fc32463c32c88eaa6 (diff) |
SQLHelpers
Diffstat (limited to 'src/com/juick/server/SQLHelpers.java')
-rw-r--r-- | src/com/juick/server/SQLHelpers.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/com/juick/server/SQLHelpers.java b/src/com/juick/server/SQLHelpers.java index 7879c244..dd3c4bc3 100644 --- a/src/com/juick/server/SQLHelpers.java +++ b/src/com/juick/server/SQLHelpers.java @@ -35,6 +35,63 @@ public class SQLHelpers { return ret; } + public static int getInt(Connection sql, String query, String param, int defvalue) { + int ret = defvalue; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement(query); + stmt.setString(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 String getString(Connection sql, String query, int param) { + String ret = null; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement(query); + stmt.setInt(1, param); + rs = stmt.executeQuery(); + if (rs.first()) { + ret = rs.getString(1); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return ret; + } + + public static String getString(Connection sql, String query, String param) { + String ret = null; + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement(query); + stmt.setString(1, param); + rs = stmt.executeQuery(); + if (rs.first()) { + ret = rs.getString(1); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return ret; + } + public static ArrayList<Integer> getArrayInteger(Connection sql, String query, int param) { ArrayList<Integer> ret = new ArrayList<Integer>(); |