Java SQL Table Create createTestTables(Statement sStatement)

Here you can find the source of createTestTables(Statement sStatement)

Description

create Test Tables

License

Open Source License

Declaration

static void createTestTables(Statement sStatement) 

Method Source Code

//package com.java2s;

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

public class Main {
    static void createTestTables(Statement sStatement) {

        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);",
                "CREATE TABLE Item(InvoiceID INTEGER,Item INTEGER,"
                        + "ProductID INTEGER,Quantity INTEGER,Cost DECIMAL(10,2)," + "PRIMARY KEY(InvoiceID,Item), "
                        + "FOREIGN KEY (InvoiceId) REFERENCES "
                        + "Invoice (ID) ON DELETE CASCADE, FOREIGN KEY (ProductId) "
                        + "REFERENCES Product(ID) ON DELETE CASCADE);" };

        for (int i = 0; i < demo.length; i++) {

            // drop table may fail
            try {
                sStatement.execute(demo[i]);
            } catch (SQLException e) {
                ;//from  w w w  . ja  va2 s  .  c o m
            }
        }
    }
}

Related

  1. createTable(Connection connection)
  2. createTable(Connection dbConn, String tableName, String columnSpec)
  3. createTable(String query)
  4. createTableAndLoadData(Statement stmt, String tableName)
  5. createTestTable(Connection conn)