-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateTable.java
More file actions
44 lines (42 loc) · 1.32 KB
/
CreateTable.java
File metadata and controls
44 lines (42 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.sql.*;
public class CreateTable {
private String table;
Statement s;
public CreateTable(String name, String schema, Statement stmt, int status)
{
table = name;
s = stmt;
String sql;
if(status == 1)
{
sql = "CREATE TABLE " + name + schema;
try{
s.execute(sql);
}catch(SQLException se){
se.printStackTrace();
System.out.println("Error in creating table " + table);
}
}
}
public void foreign_constraint(String src, String ref, String refTable, int a)
{
String sql;
sql = "Alter Table " + table + " ADD CONSTRAINT fk_"+ a + src + refTable + " FOREIGN KEY (" + src + ") REFERENCES " + refTable + "(" + ref + ")";
try{
s.executeUpdate(sql);
} catch (SQLException se) {
System.out.println("Can't add foreign key constraint in " + table);
}
}
public void insert(String attr, String record)
{
String sql;
sql = "INSERT INTO " + table + attr + " VALUES" + record;
try{
s.executeUpdate(sql);
} catch (SQLException se) {
se.printStackTrace();
// System.out.println("Unable to insert Record in table " + table);
}
}
}