• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is there named parameter in java jdbc?

 
peter tong
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there named parameter in java jdbc like
CallableStatement cstmt = conn.prepareCall("select * from table1 where column1 = :param1");
cstmt.setString("param1", "abc");
.....

I check the API and it seems it only has ordinal parameter like
CallableStatement cstmt = conn.prepareCall("select * from table1 where column1 = ?");
cstmt.setString(1, "abc");

it seems impossible to have no named parameter feature!!

[edit]Disable Smilies. CR[/edit]
[ September 08, 2008: Message edited by: Campbell Ritchie ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you look? I found this. Is that what you needed?

I think this is more of a JDBC related topic, so I shall move this thread.
 
peter tong
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, this only work for stored procedure.
I want to use named parameter for dynamic sql statement (embedded in java code), is it possible?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4028
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"?" is the only parameter and it is determined by order of parameters. Named parameters do not exist in JDBC.
 
peter tong
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Named parameters do not exist in JDBC..."
why not implement in JDBC? anyone know?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4028
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need? Numbered parameters work just fine with "?" characters, why add to the complexity of accepted values in SQL statements? Any more and you could interfere with parsing leading to all sorts of errors in the real world. In fact, even "?" characters can cause problems as I've recently discussed.

Keep in mind, java is not based on pure theory, designed by a bunch of geniuses in a think tank... its partially based on practical use in real systems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic