我知道如何使用JDBC打開數據事務。但我認爲我可以/必須做些事情來提高數據交易的性能。例如:Java數據事務性能
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;
}
}
而且當我必須關閉我的連接或開啓自動提交了嗎?
我該怎麼做才能提高我的應用程序數據事務性能?數據交易的正確方式如何?或者有什麼提示可以做得更好?
要提高插入性能使用批處理 – Marged