Exemplo n.º 1
0
  public DbConnection() throws IOException, SQLException {
    Properties props = Util.loadProperties(PROPERTIES_FILENAME);
    String dbUrl = Util.getPropertyNotNull(props, "db_url");
    String dbName = Util.getPropertyNotNull(props, "db_name");
    String dbUser = Util.getPropertyNotNull(props, "db_user");
    String dbPw = Util.getPropertyNotNull(props, "db_pw");
    debugMode = Boolean.parseBoolean(Util.getPropertyNotNull(props, "db_debug_mode"));

    if (debugMode) {
      LOGGER.warning("DATABASE DEBUG MODE ACTIVE");
    }

    con = DriverManager.getConnection(dbUrl, dbUser, dbPw);
    Statement st = con.createStatement();
    // Switch to the chosen DB
    st.executeUpdate("USE " + dbName);
    // Ensure UTF8 is used (so Korean characters are handled correctly)
    st.executeUpdate("SET NAMES utf8");
    st.close();
    connected = true;
    getInsertId = prepare("SELECT last_insert_id()", null);
  }