import java.sql.*; public final class test25 { private static String DB_URL = "jdbc:postgresql://localhost:5432/test"; private static String DB_USER = "test"; private static String DB_PASS = "test"; public static void main(String[] args) throws Exception { // load driver Class.forName("org.postgresql.Driver"); // open connection to postgres Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS); PreparedStatement stmt = null; try { conn.setAutoCommit(false); //This test assumes a table 'test' exists with one column 'cola' of type text String sql= "Insert into test (cola) values (?)"; stmt = conn.prepareStatement(sql); stmt.setString(1,"foo"); int ant = stmt.executeUpdate(); stmt.close(); stmt = null; conn.commit(); conn.close(); conn = null; } catch (SQLException ex) { conn.rollback(); conn.close(); throw ex; } } }