import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Savepoint;
import java.sql.Statement;
public class Main {
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();
conn.rollback (mySavepoint);
st.close();
conn.close();
}
private static Connection getConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:mem:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
}
|