TableMaker.java Source code

Java tutorial

Introduction

Here is the source code for TableMaker.java

Source

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

public class TableMaker {
    static String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";

    static String dbName = "Contacts";

    static String url = "jdbc:odbc:";

    static String SQLCreate = "CREATE TABLE CONTACT_INFO (" + "CONTACT_ID    INTEGER      NOT NULL   PRIMARY KEY,"
            + "ZIP           VARCHAR(10)  NOT NULL" + ");";

    public static void main(String[] args) throws Exception {
        Class.forName(jdbcDriver);
        url += dbName;
        Connection con = null;
        Statement stmt = null;
        con = DriverManager.getConnection(url);
        stmt = con.createStatement();
        stmt.execute(SQLCreate);
        con.close();
        if (con != null) {
            con.close();
        }
        if (stmt != null) {
            stmt.close();
        }

    }
}