• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

QueryRunner

 
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic