• Post Reply Bookmark Topic Watch Topic
  • New Topic

QueryRunner  RSS feed

 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you set the TO_CHAR in your select statement,
and just set colname1, coldate1, colnum1 in params ?
 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!