// 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 MySql3 {
    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))");
        Statement ins = con.createStatement();
        for(int i = 0; i < 5; i++) {
            ins.executeUpdate("INSERT INTO j VALUES(" + (i+1) + ",'Test #" + (i+1) + "')");
        }
        Statement sel = con.createStatement();
        ResultSet rs = sel.executeQuery("SELECT id,txt FROM j WHERE id > 3");
        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();
    }
}
