Skip to content

Commit 08dfe34

Browse files
committed
Experiment 10_1
1 parent 79a4626 commit 08dfe34

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import java.sql.*;
2+
3+
public class Exp10_1 {
4+
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
5+
static final String DB_URL = "jdbc:mysql://localhost/emp?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
6+
static final String USER = "root";
7+
static final String PASS = "";
8+
9+
private static final String CREATE_TABLE_SQL="CREATE TABLE employees ("
10+
+ "id INT NOT NULL,"
11+
+ "age int NOT NULL,"
12+
+ "first VARCHAR(255) NOT NULL,"
13+
+ "LAST VARCHAR(255) NOT NULL"
14+
+ ");";
15+
16+
public static void main(String[] args) {
17+
Connection conn = null;
18+
Statement stmt = null;
19+
20+
try {
21+
22+
System.out.println("Connecting to database...");
23+
conn = DriverManager.getConnection(DB_URL,USER,PASS);
24+
stmt = conn.createStatement();
25+
26+
stmt.executeUpdate(CREATE_TABLE_SQL);
27+
28+
System.out.println("Table created");
29+
30+
} catch (SQLException e) {
31+
e.printStackTrace();
32+
} finally {
33+
try {
34+
// Close connection
35+
if (stmt != null) {
36+
stmt.close();
37+
}
38+
if (conn != null) {
39+
conn.close();
40+
}
41+
} catch (Exception e) {
42+
e.printStackTrace();
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)