Java Utililty Methods SQL Table Create

List of utility methods to do SQL Table Create

  1. HOME
  2. Java
  3. S
  4. SQL Table Create

Description

The list of methods to do SQL Table Create are organized into topic(s).

Method

void createTable(Connection conn, String createTableStatement)
create Table
conn.createStatement().execute(createTableStatement);
void createTable(Connection conn, String inputSqlType, String sortOrder)
create Table
String dmlFormat = "CREATE TABLE TEST_TABLE_%s" + "(id INTEGER NOT NULL, pk %s NOT NULL, " + "kv %s "
 + "CONSTRAINT PK_CONSTRAINT PRIMARY KEY (id, pk %s))";
String ddl = String.format(dmlFormat, sortOrder, inputSqlType, inputSqlType, sortOrder);
conn.createStatement().execute(ddl);
conn.commit();
String createTable(Connection conn, String sqlText)
create Table
String tableName = parseSelectTableName(sqlText);
if (tableName.length() == 0) {
 return "";
tableName = TMP_TABLE_PREFIX + tableName + System.currentTimeMillis();
String sql = "CREATE TABLE " + tableName + " AS SELECT * FROM (" + sqlText + ") t LIMIT 0";
String dropSql = "DROP TABLE IF EXISTS " + tableName;
Statement stmt = null;
...
void createTable(Connection connection)
create Table
Statement statement = connection.createStatement();
statement.execute(CREATE_TABLE_QUERY);
void createTable(Connection dbConn, String tableName, String columnSpec)
create Table
Statement table = dbConn.createStatement();
table.execute("CREATE TABLE " + tableName + " (" + columnSpec + ")");
table.close();
void createTable(String query)
create Table
try {
 stmt = conn.createStatement();
 stmt.executeUpdate(query);
} catch (Exception e) {
 System.err.println("Got an exception! ");
 e.printStackTrace();
 System.exit(0);
void createTableAndLoadData(Statement stmt, String tableName)
create Table And Load Data
String ddl = "CREATE TABLE " + tableName + " (ID INTEGER NOT NULL PRIMARY KEY, "
 + "FNAME VARCHAR, LNAME VARCHAR)";
stmt.execute(ddl);
stmt.execute("UPSERT INTO " + tableName + " values(1, 'FIRST', 'F')");
stmt.execute("UPSERT INTO " + tableName + " values(2, 'SECOND', 'S')");
void createTestTable(Connection conn)
create Test Table
try (Statement statement = conn.createStatement()) {
 statement.execute("create table TEST (ID int, NAME varchar(8))");
void createTestTables(Statement sStatement)
create Test Tables
String[] demo = { "DROP TABLE Item IF EXISTS;", "DROP TABLE Invoice IF EXISTS;",
 "DROP TABLE Product IF EXISTS;", "DROP TABLE Customer IF EXISTS;",
 "CREATE TABLE Customer(ID INTEGER PRIMARY KEY,FirstName VARCHAR(20),"
 + "LastName VARCHAR(20),Street VARCHAR(20),City VARCHAR(20));",
 "CREATE TABLE Product(ID INTEGER PRIMARY KEY,Name VARCHAR(20)," + "Price DECIMAL(10,2));",
 "CREATE TABLE Invoice(ID INTEGER PRIMARY KEY,CustomerID INTEGER,"
 + "Total DECIMAL(10,2), FOREIGN KEY (CustomerId) "
 + "REFERENCES Customer(ID) ON DELETE CASCADE);",
...


AltStyle によって変換されたページ (->オリジナル) /