Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Callable statement syntax

 
Amol Relkar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In JDBC, we use callable statement to call stored procedure in database. Following code snippet does that work.

Assume table, and range variables declared earlier

String sql = "{call " + NEXT_KEY_PROCEDURE + "('" + table + "', " + range
+ ", ?)}";

CallableStatement cs = con.prepareCall(sql);
cs.registerOutParameter(1, Types.NUMERIC);
cs.execute();

What is the significance of curly braces {} in the syntax?
Can we use PrepareStatement to call stored procedure?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amol,
The braces are the escape syntax for stored procedures.

While using a PreparedStatement to call a stored procedure might work, it is risky because it might not. Or you could upgrade your driver and have it not work. It is better to use the intended CallableStatement subclass.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
 
Amol Relkar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic