import java.util.Date;
import java.util.HashMap;
-import org.cacert.gigi.database.DatabaseConnection;
import org.cacert.gigi.database.GigiPreparedStatement;
import org.cacert.gigi.database.GigiResultSet;
}
static {
- GigiResultSet res = DatabaseConnection.getInstance().prepare("SELECT `id`, `type_text` FROM `cats_type`").executeQuery();
- while (res.next()) {
- names.put(res.getString(2), res.getInt(1));
+ try (GigiPreparedStatement st = new GigiPreparedStatement("SELECT `id`, `type_text` FROM `cats_type`")) {
+ GigiResultSet res = st.executeQuery();
+ while (res.next()) {
+ names.put(res.getString(2), res.getInt(1));
+ }
}
ASSURER_CHALLANGE_ID = getID(ASSURER_CHALLANGE_NAME);
}
public static synchronized int getID(String name) {
Integer i = names.get(name);
if (i == null) {
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `cats_type` SET `type_text`=?");
- ps.setString(1, name);
- ps.execute();
- i = ps.lastInsertId();
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `cats_type` SET `type_text`=?")) {
+ ps.setString(1, name);
+ ps.execute();
+ i = ps.lastInsertId();
+ }
names.put(name, i);
}
return i;
}
public static void enterResult(User user, String testType, Date passDate) {
- GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("INSERT INTO `cats_passed` SET `user_id`=?, `variant_id`=?, `pass_date`=?");
- ps.setInt(1, user.getId());
- ps.setInt(2, getID(testType));
- ps.setTimestamp(3, new Timestamp(passDate.getTime()));
- ps.execute();
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `cats_passed` SET `user_id`=?, `variant_id`=?, `pass_date`=?")) {
+ ps.setInt(1, user.getId());
+ ps.setInt(2, getID(testType));
+ ps.setTimestamp(3, new Timestamp(passDate.getTime()));
+ ps.execute();
+ }
}
}