Creating a SQLServer Table to Store Java Types - Java JDBC

Java examples for JDBC:JDBC Types

Description

Creating a SQLServer Table to Store Java Types

Demo Code

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) {
    try {/*from  w w w .  ja  v  a2  s .  com*/
      Connection connection = null;
      Statement stmt = connection.createStatement();
      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 Tutorials