Prepared Statements
A prepared statement is an SQL statement whose values are determined at runtime. You can use prepared statements in the queryUsingPreparedStmt() and executePreparedStmt() functions.
When you use executePreparedStmt(), prepare the statement, for example:
String QueryCON="Insert into HR.COUNTRIES Values (?,?,?)"
Then associate the actual values at execution time, as shown in the following code snippet. It demonstrates use of executePreparedStmt() and queryUsingPreparedStmt().
Database.setCurrentConnection("/JDBC Connection"); Database.beginTransaction(); String InsQuery="INSERT into HR.COUNTRIES Values (?,?,?)"; Object []InsObj={e.rate, e.CID,e.rank}; int insertCON=Database.executePreparedStmt(InsQuery,InsObj); String UpdateQuery="UPDATE HR.COUNTRIES SET COUNTRY_ID=? WHERE COUNTRY_ID=?" Object [] update={Use.Updates,Use.UpdateV}; int updat=Database.executePreparedStmt(UpdateQuery,update); String DeleteQuery="DELETE FROM HR.COUNTRIES WHERE COUNTRY_ID=?" Object []DelObj={e.CID}; int deleteCON=Database.executePreparedStmt(DeleteQuery,DelObj); String SelectQuery="Select * from HR.COUNTRIES where HR.COUNTRIES.COUNTRY_ID>?" Object []SelObj={e.CID}; Concept []SelectCON=Database.queryUsingPreparedStmt( "/Concepts/hr/HR/COUNTRIES",SelectQuery,SelObj,true); Database.commit(); Database.unsetConnection();
Copyright © Cloud Software Group, Inc. All rights reserved.