How To Run SQL query in OAF
Prepared statement in oaf
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
-
- Expample 1:-
-
- try
- {
- Connection conn = pageContext.getApplicationModule(webBean).getOADBTransaction().getJdbcConnection();
- String query = "select REQUEST_NUMBER from mtl_txn_request_headers mtrh where mtrh.header_id="+VHEADER_ID+"";
- PreparedStatement stmt = conn.prepareStatement(query);
- // String resultset = stmt.executeQuery().toString();
- ResultSet resultset = stmt.executeQuery();
- resultset.next();
- System.out.println("Move Oredr number Is"+resultset.getInt("REQUEST_NUMBER") );
- OAHeaderBean headerBean = (OAHeaderBean)webBean.findChildRecursive("region2");
- headerBean.setText("Move Order Number "+resultset.getInt("REQUEST_NUMBER"));
- }
- catch(Exception e)
- {
- throw OAException.wrapperException(e);
- }
- Example 2:-
- try
-
- {
-
-
- Connection conn = pageContext.getApplicationModule(webBean).getOADBTransaction().getJdbcConnection();
-
- String Query = "SELECT count(*) count from XX_PA_SCO_V where project_id=:1 and CI_ID is not null";
-
- PreparedStatement stmt = conn.prepareStatement(Query);
- stmt.setString(1, project_id);
- for(ResultSet resultset = stmt.executeQuery(); resultset.next();)
- {
- pageContext.writeDiagnostics(this, "Query Executed", 1);
- result = resultset.getInt("count");;
- pageContext.writeDiagnostics(this, "Query Executed"+ result, 1);
- }
- }
-
- catch(Exception exception)
-
- {
- throw new OAException("Error in Staffing Query"+exception, OAException.ERROR);
- }
No comments:
Post a Comment