Win a copy of Hands On Software Engineering with Python this week in the Jython/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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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

Ranch Hand
Posts: 52
  • 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?

Posts: 23963
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.
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
Programmatically Create PDF Using Free Spire.PDF with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!