zoukankan      html  css  js  c++  java
  • PreparedStatement

        PreparedStatement 表示预编译的SQL语句对象。SQL语句被预编译并且存储在PreparedStatement中,然后可以使用此对象多次高效执行该SQL。

        实例:

    // 1.获取 OADBTransaction对象
    OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean); // 获取AM
    OADBTransaction txn = am.getOADBTransaction(); // 获取OADBTransaction 对象 ,其继承 DBTransaction
    PreparedStatement ps = null;
    ResultSet rs = null;

    // 2. 创建 PreparedStatement 对象
    ps = txn.createPreparedStatement(String str, int noRowsPrefetch);
    // str表示预编译的SQL语句,noRowsPrefetch 表示执行该SQL时默认获取的行数,可以是DBTransaction.DEFAULT
    eg: ps = txn.createPreparedStatement(sqlStr, 1);

    // 3.设置SQL中使用的参数的值
    ps.setLong(index,param); // ps.setShort(index,param); 以及 setInt,setString的方法为SQL设置参数的值,index为参数的顺序,param为参数的值
    eg: ps.setLong(1, Long.parseLong(this.headerId.toString())); // 设置第一个参数的值

    // 4.执行查询并返回结果
    rs = ps.executeQuery(); // 执行查询并将结果返回到ResultSet结果集中
    while(rs.next()){
    String tmp = rs.getString(1); // rs.getInt等方法
    }
  • 相关阅读:
    七种数据类型
    js字符串解析成数字
    html节点操作与事件
    form表单的默认提交行为
    CSS中的各种width(宽度)
    Javascript读写CSS属性
    ECMAScript6新特性之Reflect
    ECMAScript6新特性之String API
    ECMAScript6新特性之Array API
    判断Javascript对象是否为空
  • 原文地址:https://www.cnblogs.com/chenyongjun/p/3533609.html
Copyright © 2011-2022 走看看