JavaWeb笔记

JDBC

基本使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//注册驱动
Class.forName("com.mysql.jdbc.Driver");
//获取数据库连接对象
Connection connection = DriverManager.getConnection("jdbc:mysql://59.110.213.97:3306/test?useSSL=false",
"root", "GHn,.155070");
//定义sql语句
String sql = " insert into table_test(id,number) values(null,10086)";
//获取执行sql的对象
Statement statement = connection.createStatement();
//执行sql
int count = statement.executeUpdate(sql);
System.out.println(count);
//释放资源
statement.close();
connection.close();
阅读更多