12 月3号statement(第29、30、31天的学习)

statement是用来创建对象
Statement 对象用 Connection 的方法 createStatement 创建的
那么它创建的代码是
Connection connection = DriverManager.getConnection();
Statement statement = connection.createStatement();

Statement 对象,连接 SQL 语句将被作为参数 Statement 的方法
它的代码是
是一个查询的语句
ResultSet rs = statement.executeQuery("SELECT user_name FROM users");

Statement 接口有三个方法执行 SQL 语句的方法

执行查询语句
executeQuery
executeQuery 用于产生单个结果集  SELECT user_name FROM users;

执行更新语句
executeUpdate
executeUpdate 它执行的是 INSERT、UPDATE 、DELETE 语句以及 DDL语句,executeUpdate 的返回值是一个整数,executeUpdate 的返回值是零。

执行语句
execute
execute 执行返回多个结果集、多个更新计数还有二者组合的语句。

关掉 Statement 对象
Statement 对象将由 Java 垃圾收集程序它自己会关闭掉,在不需要 Statement 对象时显式的关闭它。

猜你喜欢

转载自xjwolaile.iteye.com/blog/1740621