I have a very simple basic question on determining the datatypes of the parameters set to a prepared statement at a run time. I searched JDBC forum but could not find any answer.
I'm writing one common Database utility class file which creates a connection, executes dynamic queries and set the results back.
my method is as below
from the above code, cleary I'm sending a string like "insert into table ? values(?,?,?)". I want this utility class file to be used across my different projects, so apparently I do have any info about what columns are there in the table. I want my calling class to be completely unaware that it is using JDBC. So it just sends a string format of the query with place holders. But I know, it should also send the parameters as method arguements. But how would my method determine the type of the parameters. I would put my resultset into collection and send it back to calling class to deal with.I do not want to have any overloaded methods also in my class because of huge permutations and combinations.
Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Ravi, I know that with Oracle database and JDBC driver, most times you can use method "setObject()". If one of the parameters is null, then you need to know the database type. And "setObject()" doesn't work with some database types like CLOB and BLOB.
As far as I know, INSERT statements don't return result sets, but for queries, you should be able to use the "getObject()" method on most occasions. Again, this may not be suitable for CLOB and BLOB columns and you may also have a problem with NULL column values.
Good Luck, Avi.
Joined: Oct 20, 2007
Yes INSERT would not result into any resultsets. I just mentioned as a an example. My intention is to replace query with any simple to complex SELECT statements. Probably my question is very vague and too ambituous. I'm also looking into other options like RowSet interface of JDBC 2.0 API. Did anyone see the benefits of RowSet?