// 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.*;

public class MySql4 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Test", "", "");
        Statement cre = con.createStatement();
        cre.executeUpdate("CREATE TABLE j(id INTEGER NOT NULL, txt VARCHAR(50), PRIMARY KEY(id))");
        PreparedStatement ins = con.prepareStatement("INSERT INTO j VALUES(?,?)");
        for(int i = 0; i < 5; i++) {
            ins.setInt(1, i+1);
            ins.setString(2, "Test #" + (i+1));
            ins.executeUpdate();
        }
        PreparedStatement sel = con.prepareStatement("SELECT id,txt FROM j WHERE id > ?");
        sel.setInt(1, 3);
        ResultSet rs = sel.executeQuery();
        while(rs.next()) {
            int id = rs.getInt(1);
            String txt = rs.getString(2);
            System.out.println(id + " : " + txt);
        }
        rs.close();
        Statement drp = con.createStatement();
        drp.executeUpdate("DROP TABLE j");
        con.close();
    }
}
