List of usage examples for java.sql Connection setAutoCommit
void setAutoCommit(boolean autoCommit) throws SQLException;
From source file:Main.java
public static void main(String[] args) throws Exception { Connection connection = null; connection.setAutoCommit(false); connection.commit();//from ww w. j a va 2s . c om }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myURL CHAR);"); String str = conn.nativeSQL("insert into survey(id) values(02)"); System.out.println(str);// w w w . j av a2s. c o m conn.commit(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st = conn.createStatement();/*from ww w . j av a 2 s .co m*/ ResultSet rs = st.executeQuery("SELECT * FROM survey"); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,myURL CHAR);"); st.executeUpdate("insert into survey(id) values(01)"); st.executeUpdate("insert into survey(id) values(02)"); Savepoint mySavepoint = conn.setSavepoint("MYSAVEPOINT"); st.executeUpdate("insert into survey(id) values(03)"); conn.commit();/*from w w w. j a va 2s. c o m*/ conn.rollback(mySavepoint); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); conn.setAutoCommit(true); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st = conn.createStatement();//from w w w.j av a 2s . c om ResultSet rs = st.executeQuery("SELECT * FROM survey"); ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); System.out.println("resultSet MetaData column Count=" + numberOfColumns); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); PreparedStatement pstmt = conn.prepareStatement("create table survey (id int, name VARCHAR(30) );"); pstmt.executeUpdate();//from w w w .ja va2 s . c o m ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st = conn.createStatement();/*from www . j a v a2 s . c om*/ ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false); Statement stmt = conn.createStatement(); stmt.executeUpdate("create table survey (id int, name CHAR(5) );"); stmt.executeUpdate("INSERT INTO survey(id, name)VALUES(111, '123456789')"); // since there were no errors, commit conn.commit();/*from ww w . ja v a2 s. c o m*/ ResultSet rs = stmt.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false); Statement stmt = conn.createStatement(); stmt.executeUpdate("create table survey (id int, name CHAR(5) );"); stmt.executeUpdate("INSERT INTO survey(id, name)VALUES(111, '123456789')"); // since there were no errors, commit conn.commit();/*from ww w .j av a 2 s . c o m*/ ResultSet rs = stmt.executeQuery("SELECT * FROM survey"); outputResultSet(rs); stmt.executeUpdate("drop table survey"); rs.close(); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); conn.setAutoCommit(false); // start a transaction Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st.executeUpdate("insert into survey (id,name ) values (2,'nameValue')"); conn.rollback(); // the preceding inserts will not commit; st.executeUpdate("INSERT INTO survey(id, name) VALUES('33', 'jeff')"); conn.commit(); // end the transaction st = conn.createStatement();//from w ww.j a v a 2s.c o m ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }