jdbc操作数据库四步骤:
public static void main(String[] args) throws ClassNotFoundException {
//1.加载驱动
Class.forName("com.mysql.jdbc.Driver");
try{
//2.连接数据库
Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/data_base?useUnicode=true&characterEncoding=utf-8","root","root");
//3.创建一个statement对象
Statement statement = connection.createStatement();
//4.执行是SQL语句
int resultSet = statement.executeUpdate("update cus_info set name = '222' where age='111' ");
System.out.println(resultSet);
}catch (Exception e){
e.printStackTrace();
}
}
本文档详细介绍了使用JDBC进行数据库操作的四个关键步骤:1. 加载MySQL驱动,2. 建立数据库连接,3. 创建Statement对象,4. 执行SQL更新语句。通过实例展示了如何设置参数并执行update语句,适合初学者理解基本操作。
4137

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



