JDBC执行顺序是什么??

package com.briup.jdbc.chap01;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class SimpleJdbc {
public static void main(String[] args) {
String dirver="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@127.0.0.1:1521:XE";
String user="oracle";
String pwd = "oracle";
Connection connection = null;
Statement statement = null;
ResultSet rSet = null;
try {
//1.注册驱动
Class.forName(dirver);
//2.建立连接
connection = DriverManager.getConnection(url, user, pwd);
//3.创建statement对象
statement = connection.createStatement();
String sql = "select * from s_dept";
String sql2 = "insert into s_dept values(102,'briup',3)";
//4.返回结果集ResultSet
//System.out.println(statement.execute(sql2));
System.out.println(statement.executeUpdate(sql2));
rSet = statement.executeQuery(sql);
//5.处理结果集
while(rSet.next()) {
System.out.println("id:"+rSet.getInt(1)+"  "
+"name:"+rSet.getString(2)+"  "
+"r_id"+rSet.getInt(3));
}
} catch (Exception e) {
e.printStackTrace();
}finally {
//关闭资源
if (rSet!=null || statement!=null || connection!=null) {
try {
rSet.close();
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}

你可能感兴趣的:(JDBC执行顺序是什么??)