Sudha,
Thanks.... i have another question about resultSet.... Below is a piece of my code ...
callableStatement cs = conn.prepareCall(sql);
:
: // register ouput parameter and set input
:
:
bFound = cs.execute();
resultSet rs = cs.getResultSet();
while (rs.next()) {
aaa = rs.getString(1);
:
:// get the output
:
}
My problem is : i always get bFound = False, what wrong with the code ?
appreciate ur guide !! Thanks
This means your stored proc is failing.
Why don't you try something like this,
if(cs.executeUpdate()==0) {
System.out.println("Executed successfully !!!");
resultSet rs = cs.getResultSet();
while (rs.next()) {
aaa = rs.getString(1);
//...
}
} else {
System.out.println("Execution failed !!!");
}
Hope this helps.
Sudha
This means your stored proc is failing.
Why don't you try something like this,
if(cs.executeUpdate()==0) {
System.out.println("Executed successfully !!!");
resultSet rs = cs.getResultSet();
while (rs.next()) {
aaa = rs.getString(1);
//...
}
} else {
System.out.println("Execution failed !!!");
}
Hope this helps.
Sudha
sudha,
shouldn't be my stored procedure is failing, because if i use cs.executeQuery(), it's working fine, just that there is an error after retrieving of the last row... that's why i use cs.execute(), to prevent the error from occuring.... but i cant go thru the while (rs.next()) loop as the rs is always NULL.
just wonder how can i solve the problem ?
> now i am confuse .... callableStatement is useful for
> update/insert and delete only ? and prepareStatement
> and statement is mainly for "SELECT" ?
You are absolutely mistaken.
You can select/update/delete/insert using Statement or PreparedStatement. CallableStatement is mainly for executing SQL Stored procedures. Why don't you read javadocs for Jdk API?
If you want to execute a single SQL statement (it doesn't matter whether it is select/insert/update/delete), you better use Statement.
If you want to execute an sql statement multiple times with different parameters, then use PreparedStatement. PrepareStatement allows you to pre-compile your statement and will be ready to accept parameters from you and execute the query.
Hope this clarifies. Don't forget the duke.
Sudha
ok ... i have a precompile SQL statement with multiple output parameters and multiple rows retrieval... i use preparedStatement in my code ... as below :
//declare variables
private Connection conn;
private PreparedStatement ps;
private resultSet rs;
GetDrCrRsnPB_Call = "begin P_GetDrCrRsnPB.SP_GetDrCrRsnPB(?,?,?,?,?,?,?,?,?,?);end;"; // this is my precompile package
ps = conn.prepareStatement(GetDrCrRsnPB_Call);
//set the input
ps.setString(1, iprodgrp);
ps.setString(2, iadjprcs);
rs = ps.executeQuery();
while (rs.next()) {
// get the output
oDrCrIndc = rs.getString(1);
:
:
:
:
}
I got the following error .... "not all variables bound" ... how can i solve this problem ? how can i register output parameter using preparedStatement ?
Please help ...