Preparedstatement and ORDER BY issue [message #111533] |
Thu, 17 March 2005 04:20 |
kalyanbitra
Messages: 2 Registered: March 2005
|
Junior Member |
|
|
Gurus,
I have created a PrepareStatement which will be used to create dynamic sql.
ex: SELECT ITEMCODE, ITEMDESC from ITEM WHERE ITEMCODE=? ORDER BY ? DESC
but when I pass
setString(1, "A")
setString(2, "ITEMCODE")
the second parameter is not taken into consideration at all when sql is executed. Then I tried the following
SELECT ITEMCODE, ITEMDESC from ITEM ORDER BY ? DESC
setString(1, "ITEMCODE")
when program executed order by clause is not taken into consideration then I removed setString but used the same sql with "?" then it gives me error all variables not bound..
I tried the following mechanism as well
SQL : SELECT ITEMCODE, ITEMDESC from ITEM ?
setString(1, "ORDER BY ITEMCODE DESC")
this gives me sql command not closed properly
so what is going on how I can create dynamic sql for ORDER BY and DESC so basically what I want to do is
SELECT ITEMCODE, ITEMDESC from ITEM ORDER BY ? ?
the reason I'm doing this I have screen where the user can go click on the column and sort either asc/desc. I want to do this dynamically instead of creating multiple sql.
|
|
|
|