Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

QueryRunner arguments don't make sense to me

 
Ranch Hand
Posts: 217
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider this code:



This question deals with QueryRunner. I understand that we have created an instance of QueryRunner named "run." However, the arguments given to the query method are throwing me off a bit due to the multiple parentheses and because it doesn't appear to be the same argument passing I am used to.

Can someone please explain to me what exactly is happening in this line:



A simple, step, by step explanation will be helpful.
 
Marshal
Posts: 3727
534
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at these javadoc pages:
    QueryRunner#query
    BeanListHandler

The parameters break-down like this:



 
M Richardson
Ranch Hand
Posts: 217
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Take a look at these javadoc pages:
    QueryRunner#query
    BeanListHandler

The parameters break-down like this:





So in simple terms, it is saying:

Line 1. Run this SQL statement and return me the result as a List.
Line 3. Mr. BeanListHandler, you know what to do with results that are in the form of lists, so please handle this result (How? I'm not too sure)
Line 4. Query parameters.... I don't get this part. How do the parameters exactly correspond to the data? What is the ordering? Can you give an example using this code using made-up data?

Can you please explain this to me in very simple terms? Thanks

 
Ron McLeod
Marshal
Posts: 3727
534
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've never used this API, so my understanding is based on what the documentation says.

QueryRunner#query: executes the given SELECT SQL query and returns a result object [using replacement parameters].
ResultSetHandler: implementations of this interface convert ResultSets into other objects.
BeanListHandler: implementation [of ResultSetHandler] that converts a ResultSet into a List of beans.

The BeanListHandler takes the rows from the ResultSet and converts them in to beans.  In your example, the beans are of type Ret41Data.

The query parameters are the values which are substituted in the prepared statement which was created based on the SQL statement.



For example, if the SQL statement was:
SELECT ticket_number, issuance_date FROM overdue_fines WHERE plate_number=? AND province_code=?

then the query parameters might look something like:
"DDX453G", "BC"

and the bean might be resemble:

The the usage could be something like:


I've only looked at this API for a few minutes, so don't take everything to be 100% correct, but I think the concepts are correct.

Maybe someone who has worked with this API before can provide more information.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic