Java tutorial
//package com.java2s; import java.sql.Types; public class Main { /** * Creates a SQL statement to create a table. Creates an aditional field * called GDBMSINDEX with the autonumeric primary key constraint * * @param tableName * Name of the table to be created * @param names * names of the fields * @param types * types of the fields. Must have the same length than names * * @return SQL statement */ public static String getCreateStatementWithAutonumeric(String tableName, String[] names, int[] types) { StringBuffer sql = new StringBuffer("CREATE CACHED TABLE "); sql.append(tableName).append(" ("); for (int i = 0; i < types.length; i++) { sql.append(names[i]).append(" ").append(getTypeString(types[i])).append(", "); } sql.append("GDBMSINDEX INTEGER IDENTITY"); // close the instruction sql.append(")"); return sql.toString(); } /** * Gets the name of the type to be used with the internal dbms * * @param type * java.sql.Types constant * * @return String * * @throws RuntimeException * If the Type is not recognized */ public static String getTypeString(int type) { switch (type) { case Types.BIGINT: return "BIGINT"; case Types.BIT: case Types.BOOLEAN: return "BOOLEAN"; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return "VARCHAR"; case Types.DATE: return "DATE"; case Types.DECIMAL: case Types.NUMERIC: case Types.FLOAT: case Types.DOUBLE: case Types.REAL: return "DOUBLE"; case Types.INTEGER: return "INTEGER"; case Types.SMALLINT: return "SHORT"; case Types.TINYINT: return "BYTE"; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return "BINARY"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.TIME: return "TIME"; default: throw new RuntimeException("Cannot edit the type: " + type); } } }