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( );
}