X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FDatabaseConnection.java;h=661565d843a0a3f1b428a8f114d6c92cfc34129f;hp=21d701cb4bc4048589fcd845040e5660a405912d;hb=a1a980dd0cc65f33a6189eb81a164fe79abb647c;hpb=d895448cb685adc4c2bfac8d92759252d2ce8c36 diff --git a/src/org/cacert/gigi/database/DatabaseConnection.java b/src/org/cacert/gigi/database/DatabaseConnection.java index 21d701cb..661565d8 100644 --- a/src/org/cacert/gigi/database/DatabaseConnection.java +++ b/src/org/cacert/gigi/database/DatabaseConnection.java @@ -15,7 +15,7 @@ public class DatabaseConnection { private Connection c; - private HashMap statements = new HashMap(); + private HashMap statements = new HashMap(); private static Properties credentials; @@ -34,7 +34,7 @@ public class DatabaseConnection { private void tryConnect() { try { c = DriverManager.getConnection(credentials.getProperty("sql.url") + "?zeroDateTimeBehavior=convertToNull", credentials.getProperty("sql.user"), credentials.getProperty("sql.password")); - PreparedStatement ps = c.prepareStatement("SET SESSION wait_timeout=?;"); + PreparedStatement ps = c.prepareStatement("SET SESSION wait_timeout=?, time_zone='+0:00';"); ps.setInt(1, CONNECTION_TIMEOUT); ps.execute(); ps.close(); @@ -44,11 +44,15 @@ public class DatabaseConnection { } } - public PreparedStatement prepare(String query) throws SQLException { + public GigiPreparedStatement prepare(String query) { ensureOpen(); - PreparedStatement statement = statements.get(query); + GigiPreparedStatement statement = statements.get(query); if (statement == null) { - statement = c.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); + try { + statement = new GigiPreparedStatement(c.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)); + } catch (SQLException e) { + throw new Error(e); + } statements.put(query, statement); } return statement; @@ -71,14 +75,6 @@ public class DatabaseConnection { lastAction = System.currentTimeMillis(); } - public static int lastInsertId(PreparedStatement query) throws SQLException { - ResultSet rs = query.getGeneratedKeys(); - rs.next(); - int id = rs.getInt(1); - rs.close(); - return id; - } - private static ThreadLocal instances = new ThreadLocal() { @Override