· 8 years ago · Apr 19, 2018, 12:30 PM
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6package com.ipstep.jdbc;
7
8import java.sql.Connection;
9import java.sql.SQLException;
10import java.sql.Statement;
11
12/**
13 *
14 * @author user
15 */
16public class CreateTables {
17
18 public void createTable(Connection conn) throws SQLException{
19
20
21 Statement stmt = conn.createStatement();
22 String sql = "CREATE TABLE IF NOT EXISTS FACULTY "
23 + "(ID INT PRIMARY KEY NOT NULL,"
24 + " NAME TEXT NOT NULL, "
25 + " FAMILY TEXT NOT NULL, "
26 + " F_NUM INT) ";
27 //+ " SALARY REAL)";
28 stmt.execute(sql);
29 stmt.close();
30
31 System.out.println("Table created successfully");
32 }
33public void deleteTable(Connection conn)throws SQLException{
34 Statement st = conn.createStatement();
35 String sql = "drop table company";
36 st.execute(sql);
37 st.close();
38 conn.close();
39 System.out.println("Table was droped!");
40}
41
42}