• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to determine datatypes of the parameters runtime

 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

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.

Any ideas?
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Avi,

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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic