I know how to open data transaction with JDBC. But i think I can/must do something to increase data transaction performance. For example:
public class F_Koneksi { private static final String JDBC_DRIVER; private static final String DB_URL; private static final String USER; private static final String PASS; static { JDBC_DRIVER = "org.postgresql.Driver"; DB_URL = "jdbc:postgresql://localhost:5432/MyDatabase"; USER = "Username"; PASS = "Password"; } private final Connection con; private ResultSet rs; private Statement stmt; public F_Koneksi() { Connection connect; try { Properties props = new Properties(); props.setProperty("user", USER); props.setProperty("password",PASS); props.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory"); props.setProperty("ssl", "true"); forName(JDBC_DRIVER); connect = getConnection(DB_URL, props); } catch (SQLException|ClassNotFoundException se) { connect = null; } con = connect; } public boolean Update(String Query) { try { Query = Query.replaceAll("`", "\""); System.out.println(Query); Statement stmt = con.createStatement(); stmt.executeUpdate(Query); return true; } catch (SQLException ex) { ex.printStackTrace(); return false; } } And when i must close my connection or turning auto commit off?
What can I do to improve my app data transaction performance? How is the proper way to make data transaction? Or any tips to do it better?