This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

preparedstatment and order by ?

 
sandy yang
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can I use prepareStatement to sort my records?
I have the following code:
private PreparedStatement custQuery;
custQuery = connection.prepareStatement( " SELECT * FROM CUSTOMERS ORDER BY ? " );
try {
custQuery.setInt(1, "CUST_NUM");
RsultSet results = custQuery.executeQuery();
.....
.....
more code
"CUST_NUM" is the column name of customer table, datebase is oracle9i.
when I display my results, customer records is not ordered by customer number.
if I change my preparedStatement to "SELECT * FROM CUSTOMERS ORDER BY CUST_NUM", the results will sort correctly.
any one have any ideas? thanks!
 
sandy yang
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did try both "setString(1, "CUST_NUM");" and "setInt(1, 1);". customer number is my customer table's 1st column and CUST_NUM is the column name.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic