java管理系统类源代码 javaweb简单管理系统源码( 三 )


? {? = call procedure_name[(?, ?, ...)]}
? {call procedure_name}
CallableStatement语句
? 其中的问号是参数占位符,参数共有两种:
? IN参数
? OUT参数
? IN参数使用setter方法来设置
? OUT参数则使用registerOutParameter方法来设置
CallableStatement 语句
CallableStatement cstmt = con.prepareCall
("{call getTestData(?, ?)}");
cstmt.registerOutParameter
(1, java.sql.Types.TINYINT);
cstmt.registerOutParameter
(2, java.sql.Types.DECIMAL, 3);
cstmt.executeQuery();
byte x = cstmt.getByte(1);
java.math.BigDecimal n =
cstmt.getBigDecimal(2, 3);
第二讲 第五部分
结 果 集
结果集
? JDBC为了方便处理查询结果,又专门定义了一个接口,这个接口就是ResultSet接口 。ResultSet接口提供了可以访问数据库查询结果的方法,通常称这个接口所指向的对象为结果集 。
? 有两种方法得到结果集 , 一种是直接执行查询语句 , 将结果存储在结果集对象上;另一种是不存储返回结果,而在需要时调用数据库语句的getResultSet方法来返回结果集
结果集
? 结果集指针
由于返回的结果集可能包含多条数据记录 , 因此ResultSet 接口提供了对结果集的所有数据记录轮询的方法 。结果集自动维护了一个指向当前数据记录的指针 , 初始时这个指针是指向第一行的前一个位置 。next 方法就是用于向前移动指针的
结果集
? 结果集属性
默认情况下,结果集是一个不可更新集 , 并且结果集的指针也只能向前移动 。也就是说,在得到了一个结果集之后,用户只能按照从第一条记录到最后一条记录的顺序依次向后读?。?而不能跳到任意条记录上,也不能返回到前面的记录 。不仅如此,结果集的这种轮询只能进行一次,而不能再将指针重置到初始位置进行多次轮询
结果集
? 结果集属性
类型
并发性
有效性
? 属性的设置是在生成数据库语句时通过向生成方法传入相应的参数设定的,而当结果集已经返回时就不能够再改变它的属性了 。
结果集生成Statement语句共有三种方法
public Statement createStatement() throws SQLException;
public Statement createStatement
(int resultSetType, int resultSetConcurrency)
throws SQLException;
public Statement createStatement
(int resultSetType, int resultSetConcurrency,
int resultSetHoldability)
throws SQLException;
结果集
? 生成PreparedStatement语句共有六种方法
public PreparedStatement prepareStatement(String sql) throws SQLException;
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException;
public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
throws SQLException;
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency)
throws SQLException;
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException;
public PreparedStatement prepareStatement(String sql. String[] columnNames)
throws SQLException;
结果集
? 生成CallableStatement语句共有三种方法
public CallableStatement prepareCall(String sql)
throws SQLException;
public CallableStatement prepareCall
(String sql, int resultSetType,
int resultSetConcurrency)
throws SQLException;
public CallableStatement prepareCall
(String sql, int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
throws SQLException;

推荐阅读