| Author |
QueryRunner
|
jeff mutonho
Ranch Hand
Joined: Apr 30, 2003
Posts: 271
|
|
I'm trying to use the QueryRunner from the commons DBUtils to do a select from an oracle database.My code looks as follows : params is an array of the columns I wish to specify in my SELECT statement and contains the following colname1, TO_CHAR(coldate1,'YYYY-MM-DD HH24:MI:SS'), TO_CHAR(colnum1,'99999990.99') When I run this I get an exception saying :
java.sql.SQLException: Invalid column type Query: SELECT (?, ?, ?) FROM schema.table Parameters: [colname1, TO_CHAR(coldate1,'YYYY-MM-DD HH24:MI:SS'), TO_CHAR(colnum1,'99999990.99')] at org.apache.commons.dbutils.QueryRunner.rethrow(QueryRunner.java:330) at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:213) at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:279) at co.za.scs.scvpull.SCVDatabaseToMessagingClient.selectRows(SCVDatabaseToMessagingClient.java:192) at co.za.scs.scvpull.SCVDatabaseToMessagingClient.main(SCVDatabaseToMessagingClient.java:60)
Does this mean , one cannot have a select statement that takes arguments specified as : SELECT (?, ?, ?) FROM schema.table jeff mutonho
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
|
|
Why don't you set the TO_CHAR in your select statement, and just set colname1, coldate1, colnum1 in params ?
|
[My Blog]
All roads lead to JavaRanch
|
 |
jeff mutonho
Ranch Hand
Joined: Apr 30, 2003
Posts: 271
|
|
I can't because the decision whether or not to do the formatting(i.e adding TO_CHAR) is based on each parameter having formatting info as shown in the method below:
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
|
|
I'm not a pro about this, but can you actually pass parameters for column names ? Shouldn't that be used for items values only ? Please confirm my doubt first
|
 |
jeff mutonho
Ranch Hand
Joined: Apr 30, 2003
Posts: 271
|
|
Yes you can.I tested with a single column(with no TO_CHAR stuff) and it worked .Anyway I've changed the whole implementation to return the generated SQL as follows: and then call QUeryRunner as follows : i.e pass a null object for the parameter array.Works
|
 |
 |
|
|
subject: QueryRunner
|
|
|