I have an sql string (with placeholders ('?') )as an input into my code. I am trying to generate query classes based on this input sql. I need to figure out what the columns are that this sql string is looking for, and from which tables. Is there any method(s) in JDBC to which I can pass in this sql string (without setting the placeholders since I don't know what the values should be) and get back information about the columns the sql is looking for ? I don't want to parse the input sql since that could be a daunting task... Thanks, - krishnan
Krishnan Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy. Thanks again and we hope to see you around the ranch!!
Joined: May 10, 2001
Now for your question: I think your going to have to post your code because I have no idea what your asking Do you mean to say your getting a user entered query at run time and want to find out about it before you execute it? If so then unless you already have all of the info defined in your code your going to have to run the query in order to get some metadata from the result set. Post some code or a good example of what your doing and I might be able to help more.
Joined: Mar 15, 2002
Thanks for your mail, dave. Here is what I am trying to do. Given the following query: select first_name = rtrim(first_name), last_name = rtrim(last_name) from tbl_table1 where id1 = ? and id2 = ? and id3 = ? I want to write a utility to create a Java class for this query. This class will have items in the "select" clause as data members (first_name, last_name), get and set methods (to set the "where" clause parameters), and an execute() method to run the query. The user can then create such classes for any sql query using this utility, and use these clsses to query instead of dealing with the dbms directly. I want to avoid having to parse the sql string to get the columns being "select"ed, since this could get complicated. I do not know what valid inputs will be, so I do not want to have to set dummy values for parameters in my query. Is there a way I can use JDBC to get me the columns that this query will select, and the data types, as a metadata or something ? Hope that clears my question, - krishnan