-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJdbcDemo05.java
More file actions
50 lines (43 loc) · 1.31 KB
/
Copy pathJdbcDemo05.java
File metadata and controls
50 lines (43 loc) · 1.31 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
50
package jdbc;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.Statement;
/**
* @author : CodeWater
* @create :2022-03-08-16:45
* @Function Description :DDL语句,创建表
*/
public class JdbcDemo05 {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql:///db3", "root", "root");
String sql = "create table student( id int , name varchar(20) ) ";
stmt = conn.createStatement();
int count = stmt.executeUpdate(sql);
System.out.println(count);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}