Creating a SQLServer Table to Store Java Types : SqlServer « Database « Java Tutorial






import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {
  public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    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);
  }
}








20.39.SqlServer
20.39.1.Load driver for SQL Server
20.39.2.Connect to a database and read from table
20.39.3.Creating a SQLServer Table to Store Java Types
20.39.4.Create a sensitive scrollable result set
20.39.5.Getting the Number of Rows in a Table Using a Scrollable Result Set
20.39.6.Determining If a Database Supports Updatable Result Sets: An updatable result set allows modification to data in a table through the result set.
20.39.7.Updating a Row in a Database Table Using an Updatable Result Set
20.39.8.Calling a Stored Procedure in a Database with no parameters
20.39.9.Get all table schemas
20.39.10.Connect to database and call stored procedure
20.39.11.Call a stored procedure with no parameters and return value.
20.39.12.Get all table catalogs