Tuesday, 31 October 2017

Oracle ADF Prepared Statements for Calling Select Statement

Oracle ADF Prepared Statements for Calling Select Statement

public boolean checkForEmployeeRec(String fname,String lname)
{
   PreparedStatement cps=getDBTransaction().createPreparedStatement("select * from emp where firstname=? and lastname=?",0);
Boolean result = Boolean.FALSE;
ResultSet resultSet = null;
try {
  cps.setString(1,fname);
  cps.setString(2,lname);
  resultSet = cps.executeQuery();
  if (resultSet.next() )
  {
     result = Boolean.TRUE;
  }
 }catch (SQLException e) {
 e.printStackTrace();
} finally {
   try {
    resultSet.close();
    cps.close();
  }catch(SQLException sqle) {
     sqle.printStackTrace();
}
}
return result;
}

public void insertStudent(String name) {

String strQuery = "insert into Student values(std_seq.nextval,'"+name+"')";

DBTransaction dbTransaction = this.getDBTransaction();

Statement stmt = dbTransaction.createStatement(1);

int result=0;

try {

result = stmt.executeUpdate(strQuery);
dbTransaction.commit();

} catch (SQLException e) {
e.printStackTrace();
}
}

No comments:

Post a Comment