This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

How to run SQL query retrieved after running preparedstatement ?  RSS feed

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I've a SQL query stored in SQLQUERY column of the database and I am using the following SQL statement to retrieve it : SELECT SQLQUERY FROM MYTABLE WHERE dataid = ? as shown below in my try block (only part of code is shown for brevity purpose)



So, in the code above, the resultset object rs is holding the value of the `SQLQUERY` column corresponding to the dataid. Say for example, the value retrieved is "SELECT * FROM TABLE2 WHERE empID = 101".


How can I run the value (which is the SQL) so that the result set object would hold its column values?

Thanks
 
Marshal
Posts: 24188
54
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, actually the ResultSet is holding a collection of zero or more rows, each of which contains a single column. And that column contains a string (I assume) which is an SQL query.

So the first step is to iterate through the ResultSet and get that string out of each of those rows. I expect you already know how to do that, if not then every tutorial ever written about JDBC will have an example very near the beginning.

And once you have a String value which contains an SQL query... I expect you already know how to create a Statement which uses an SQL query, no?

Hope that helps, if it isn't clear now then ask for clarification about the parts you still don't understand.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!