Create a MySQL Table to Store Java Types (Using Statement Objects)? : MySQL « Database « Java Tutorial






StringBuffer tableString = new StringBuffer("CREATE TABLE mysql_all_types(");
    //                    Column Name          MySQL Type          Java Type
    tableString.append("column_boolean       BOOL, ");              // boolean
    tableString.append("column_byte          TINYINT, ");           // byte
    tableString.append("column_short         SMALLINT, " );         // short
    tableString.append("column_int           INTEGER, " );          // int
    tableString.append("column_long          BIGINT, " );           // long
    tableString.append("column_float         FLOAT, "    );         // float
    tableString.append("column_double        DOUBLE PRECISION, ");  // double
    tableString.append("column_bigdecimal    DECIMAL(13,0), "   );  // BigDecimal
    tableString.append("column_string        VARCHAR(254), "    );  // String
    tableString.append("column_date          DATE, "            );  // Date
    tableString.append("column_time          TIME, "             ); // Time

    tableString.append("column_timestamp     TIMESTAMP, "         );// Timestamp
    tableString.append("column_asciistream1  TINYTEXT, "  );  // Clob (< 2^8 bytes)
    tableString.append("column_asciistream2  TEXT, "       ); // Clob (< 2^16 bytes)
    tableString.append("column_asciistream3  MEDIUMTEXT, " ); // Clob (< 2^24 bytes)
    tableString.append("column_asciistream4  LONGTEXT, "   ); // Clob (< 2^32 bytes)
    tableString.append("column_blob1         TINYBLOB, "  );  // Blob (< 2^8 bytes)
    tableString.append("column_blob2         BLOB, "      );  // Blob (< 2^16 bytes)
    tableString.append("column_blob3         MEDIUMBLOB, " ); // Blob (< 2^24 bytes)
    tableString.append("column_blob4         LONGBLOB)"   ); // Blob (< 2^32 bytes)

    stmt.executeUpdate(tableString.toString());

//From Book: JDBC Recipes A Problem-Solution Approach









20.34.MySQL
20.34.1.Get a MySQL Connection from the Driver Manager
20.34.2.JDBC Mysql Connection String
20.34.3.MySQL Connection Properties: Passing Additional Properties Using a Database URL
20.34.4.Keep the Connection Alive for MySQL
20.34.5.MySQL Data type to Java Data type Conversion Table
20.34.6.Create a MySQL Table to Store Java Types (Using Statement Objects)?
20.34.7.Retrieve Automatically Generated Keys Using a Statement (MySQL)?
20.34.8.Creating a MySQL Table to Store Java Types
20.34.9.Loading a Flat File to a MySQL Table, file is comma-separated
20.34.10.Loading a Flat File to a MySQL Table, file is terminated by \r\n, use this statement
20.34.11.Creating a Database in MySQL
20.34.12.Creating a MySQL Database Table to store Java Types
20.34.13.Deleting a Table from Database
20.34.14.Retrieving Tables from a Database
20.34.15.Inserting values in MySQL database table
20.34.16.Getting the Number of Rows in a Database Table
20.34.17.Updating a Row in a Database Table
20.34.18.Deleting All Rows from a Database Table
20.34.19.Exporting a MySQL Table to a Flat File
20.34.20.Retrieve auto-generated keys
20.34.21.MySQL Error code and message