wood burning stoves*
The moose likes JDBC and the fly likes is there named parameter in java jdbc? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "is there named parameter in java jdbc?" Watch "is there named parameter in java jdbc?" New topic
Author

is there named parameter in java jdbc?

peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
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

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Mar 15, 2008
Posts: 240
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

Joined: Oct 23, 2005
Posts: 3716
    
    5

"?" is the only parameter and it is determined by order of parameters. Named parameters do not exist in JDBC.


My Blog: Down Home Country Coding with Scott Selikoff
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
"Named parameters do not exist in JDBC..."
why not implement in JDBC? anyone know?
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is there named parameter in java jdbc?