Hi deech,
Try :
>
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
>
> public class UpdateTest {
> private Connection conn;
>
> private Connection createConnection () throws SQLException,
> ClassNotFoundException {
> Class<?> t = Class.forName("org.h2.Driver");
> Connection conn = DriverManager.getConnection("jdbc:h2:mem", "sa",
> "");
> conn.setAutoCommit(false);
> return conn;
> }
>
> private void populateTable(Connection conn) throws SQLException {
> conn.createStatement().execute("INSERT INTO TEST VALUES('hello')");
> }
>
> private void updateTable(Connection conn) throws SQLException {
> Statement s = conn.createStatement();
> s.execute("UPDATE TEST SET string = 'goodbye'");
> }
>
> private void printTable(Connection conn) throws SQLException {
> StringBuilder s = new StringBuilder();
> try {
> ResultSet result = conn.createStatement().executeQuery("SELECT *
> FROM Test");
> result.next();
> System.out.println(result.getString(1));
> }
> catch (SQLException e) {
> e.printStackTrace();
> }
> }
>
> public UpdateTest () throws SQLException, ClassNotFoundException {
> this.conn = this.createConnection();
> this.conn.createStatement().execute("DROP TABLE IF EXISTS TEST");
> this.conn.createStatement().execute("CREATE TABLE IF NOT EXISTS TEST
> (string VARCHAR)");
> this.populateTable(conn);
conn.commit();
> this.updateTable(conn);
conn.rollback();
> this.printTable(conn);
> }
>
> public static void main (String[]args) throws SQLException,
> ClassNotFoundException{
> UpdateTest t = new UpdateTest();
> }
>
> }
The original code had no commit and printTable was seeing a
transaction in progress.
Regards,
Peter
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.