-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.java~
More file actions
49 lines (49 loc) · 1.27 KB
/
Database.java~
File metadata and controls
49 lines (49 loc) · 1.27 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
45
46
47
48
49
import org.h2.Driver;
import java.sql.*;
public class Database
{
public static void main(String[] args)
{
Connection conn =null;
Statement stmt =null;
try
{
Class.forName("org.h2.Driver");
conn=DriverManager.getConnection("jdbc:h2:~/mytest","sa","");
stmt=conn.createStatement();
String create;
create = "CREATE TABLE IF NOT EXISTS STUDENT (NAME TEXT, ID TEXT NOT NULL, CGPA FLOAT, PRIMARY KEY(ID))";
stmt.executeUpdate(create);
conn.setAutoCommit(false);
String query;
query = "INSERT INTO STUDENT VALUES ('ABHISHEK','2013A7PS810G',9.81)";
stmt.addBatch(query);
query = "INSERT INTO STUDENT VALUES ('AKSHAY','2013A5PS310G',8.41)";
stmt.addBatch(query);
query = "INSERT INTO STUDENT VALUES ('VATAN','2013A3PS540G',9.52)";
stmt.addBatch(query);
stmt.executeBatch();
conn.commit();
}catch(SQLException e)
{
System.out.println("Caught SQLException error 11");
e.printStackTrace();
}catch(Exception e)
{
System.out.println("Caught an Exception error 12");
e.printStackTrace();
}
finally{
try{
if(conn!=null)
conn.close();
}catch(SQLException e)
{
System.out.println("Caught SQLException error 13");
}catch(Exception e)
{
System.out.println("Caught an Exception error 14");
}
}
}
}