This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Callable statement return false on execute

 
marie menetrieux
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I have a problem with a callable statement, the execute always return false whereas the procedure called work fine in sql+
If you have any idea please tell me ...
thanks

the procedure is :
PROCEDURE test IS
tr_id NUMBER;
BEGIN
tr_id :=2;
END;
-----

the simplified class is :

public class testcall {
private static Connection myConnection;
public static void main(String[] args) {
System.out.println("debut test");
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
myConnection = DriverManager.getConnection("jdbc racle:thin:@bermudes:1521:EAGLE","training", "training");
boolean resExec = true;
String end_date_query = "{ call training.pck_user_job.test }";
CallableStatement cStmt = myConnection.prepareCall(end_date_query);

resExec = cStmt.execute();
cStmt.close();
System.out.println("updateUserJob ben alors ? "+resExec);
}catch(Exception e){
System.out.println("pb "+e);
}
}
}
 
marie menetrieux
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact I found the solution, after one day of searches, in an other forum. I was wrong in the interpretation of the boolean returned by execute :
"I have no idea what SQL you are executing, but in the Java documentation it says;
Returns:
true if the next result is a ResultSet object; false if it is an update count or there are no more results
So, if you are doing an insert, then the return would always be false.
If you want to know if you were successfull with your insert, you can use executeUpdate instead. This will return the number of rows that were updated, so if it's > 0 then you were succesful. "
may be it will help other people
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic