// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class ToughH2 {
    public static void main(String[] args) throws Exception {
        Class.forName("org.h2.Driver");
        Connection con = DriverManager.getConnection("jdbc:h2:file:/test;ALLOW_LITERALS=ALL", "sa", "");
        Statement stmt = con.createStatement();
        stmt.executeUpdate("CREATE TABLE t1(f1 INTEGER PRIMARY KEY, f2 VARCHAR(50))");
        stmt.close();
        con.close();
        con = DriverManager.getConnection("jdbc:h2:file:/test;ALLOW_LITERALS=NONE", "sa", "");
        stmt = con.createStatement();
        //stmt.executeUpdate("INSERT INTO t1 VALUES(1,'A')");
        //stmt.executeUpdate("INSERT INTO t1 VALUES(2,'BB')");
        //stmt.executeUpdate("INSERT INTO t1 VALUES(3,'CCC')");
        PreparedStatement pstmt = con.prepareStatement("INSERT INTO t1 VALUES(?,?)");
        pstmt.setInt(1, 1);
        pstmt.setString(2, "A");
        pstmt.executeUpdate();
        pstmt.setInt(1, 2);
        pstmt.setString(2, "BB");
        pstmt.executeUpdate();
        pstmt.setInt(1, 3);
        pstmt.setString(2, "CCC");
        pstmt.executeUpdate();
        pstmt.close();
        ResultSet rs = stmt.executeQuery("SELECT * FROM t1");
        while(rs.next()) {
            int f1 = rs.getInt(1);
            String f2 = rs.getString(2);
            System.out.println(f1 + " " + f2);
        }
        rs.close();
        stmt.executeUpdate("DROP TABLE t1");
        stmt.close();
        con.close();
    }
}
