package com.itheina;
import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class JdbcTest {
/**
* JDBC入门程序
*/
@Test
public void testUpdate() throws Exception {
//1.注册驱动
Class.forName("com.mysql.jdbc.Driver");
//2.获取数据库连接
String url = "jdbc:mysql://localhost:3306/db02";
String username = "root";
String password = "123456";
Connection connection = DriverManager.getConnection(url, username, password);
//3.获取SQL语句执行对象
Statement statement =connection.createStatement();
//4.SQL语句执行对象,执行SQL语句,返回结果集
int result =statement.executeUpdate("update user set age=25 where id=1");//DML
System.out.println("SQL语句执行完毕影响的记录数为:"+ result);
//5.释放资源
statement.close();//释放Statement对象
connection.close();//关闭连接
}
}
结果

我们可以看到年龄已经被修改


被折叠的 条评论
为什么被折叠?



