// 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.*;
import java.util.regex.*;

public class MySqlEnum {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Test", "root", "");
        Statement stmt = con.createStatement();
        stmt.executeUpdate("CREATE TABLE et (ef ENUM('A','B','C'))");
        // only returns 'enum'
        ResultSet md = con.getMetaData().getColumns("Test", null, "et", "ef");
        if(md.next()) {
            System.out.println(md.getString("TYPE_NAME"));
        }
        md.close();
        // only returns 'enum'
        ResultSet is = stmt.executeQuery("SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='et' AND COLUMN_NAME='ef'");
        while(is.next()) {
            System.out.println(is.getString("DATA_TYPE"));
        }
        is.close();
        // returns something parsable
        ResultSet sc = stmt.executeQuery("SHOW COLUMNS FROM et LIKE 'ef'");
        while(sc.next()) {
            System.out.println(sc.getString("Type"));
            Pattern p = Pattern.compile("'(\\w+)'");
            Matcher m = p.matcher(sc.getString("Type"));
            while (m.find()) {
               System.out.println(m.group(1));
            }
        }
        sc.close();
        stmt.executeUpdate("DROP TABLE et");
        con.close();
    }
}
