The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.sql  [73 examples] > Tables  [6 examples]

e250. Creating a SQLServer Table to Store Java Types

This example creates a SQLServer table called sqlserver_all_table to store Java types.
    try {
        Statement stmt = connection.createStatement();
    
        //     Column Name          SQLServer Type           Java Type
        String sql = "CREATE TABLE sqlserver_all_table("
            + "col_boolean          BIT, "                // boolean
            + "col_byte             TINYINT, "            // byte
            + "col_short            SMALLINT, "           // short
            + "col_int              INTEGER, "            // int
            + "col_float            REAL, "               // float
            + "col_double           DOUBLE PRECISION, "   // double
            + "col_bigdecimal       DECIMAL(13,0), "      // BigDecimal; can also be NUMERIC(p,s)
            + "col_string           VARCHAR(254), "       // String
            + "col_date             DATETIME, "           // Date
            + "col_time             DATETIME, "           // Time
            + "col_timestamp        TIMESTAMP, "          // Timestamp
            + "col_characterstream  TEXT, "               // CharacterStream or AsciiStream (< 2 GBytes)
            + "col_binarystream     IMAGE)";              // BinaryStream (< 2 GBytes)
    
        stmt.executeUpdate(sql);
    } catch (SQLException e) {
    }

 Related Examples
e245. Creating a Database Table
e246. Deleting a Database Table
e247. Listing All Table Names in a Database
e248. Creating a MySQL Table to Store Java Types
e249. Creating an Oracle Table to Store Java Types

See also: Batching    Connections    Database Meta Data    Deleting Data    Drivers    Importing and Exporting    Inserting and Updating Data    Oracle OBJECTs    Oracle VARRAYs    Procedures and Functions    Retrieving Data    Scrollable Result Sets    Updatable Result Sets   


© 2002 Addison-Wesley.