jdbc-prepare sql

1 prepared sql
oracle provide two kinds of prepared SQL prepared statements and store procedures.Prepared SQL provide an advantage over the simple sql statements you have convered so far.if you execute the same prepared sql more than once,the database remains ready for your sql without having to rebuild the query plan.
 1) Prepared Statements
 PreparedStatement statement=conn.preparedStatement(
     "update account set balance=? where id=?");
 for(int i=0;i<accounts.length;i++){
    statement.setFloat(1,accounts[i].getBalance());
    statement.setInt(2,i);
    statement.execut();
    stateement.clearParameters();
 }
 commit();
 statement.close;
 2) Stored Procedure
 try {
    CallableStatement statement;
    int i;
 
    statement = c.prepareCall("{call sp_interest[(?,?)]}");
 
    statement.registerOutParameter(2, java.sql.Types.FLOAT);
    for(i=1; i<accounts.length; i++) {
        statement.setInt(1, accounts[i].getId( ));
        statement.execute( );
        System.out.println("New balance: " + statement.getFloat(2));
    }
    c.commit( );
    statement.close( );
    c.close( );
}

posted on 2006-10-11 14:38 康文 阅读(373) 评论(0)  编辑  收藏 所属分类: java


只有注册用户登录后才能发表评论。


网站导航:
 
<2006年10月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜