Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to join multiple tables using Spring JDBC Template?

Tags:

spring-jdbc

I am newbie to Java Spring and learning JDBC template to access database. Now i have 3 relational tables and i need to join them using JDBC template and need to print the result. How can i implement it. Any working example will sure help me a lot.

Thanks

like image 618
Manish Avatar asked Jan 19 '14 07:01

Manish


1 Answers

You're really asking a multi-facetated question. I have provided links to of SOs and posts below, but there is many many more answers out there. If these aren't of any use just search for another one there are literally hundreds of posts out there all on the same subject.

  1. you need a query that'll combine three tables into one query (you don't mention if you'll need nested joins, or a simple join three times). For that i suggest you read up on some SQL. Here is a post that will give you an example to a nested select and links to multiple other posts explaining different SQL.

  2. You need to use Spring JDBC (you don't mention which specific template implementation you are using). Here is post that gives you RowMapper examples and the logic to iterate over the results.

  3. you require logic to iterate over the results. This is done most easily with Springs RowMapper or ResultSetExtractor interfaces. Here is a post that'll explain the differences between the two and link to the API (which I recommend you read).

ResultSetExtracor Implementation Example - plus iteration logic

RowMapper Implementation Example - plus iteration logic

like image 65
Prancer Avatar answered Jan 01 '23 12:01

Prancer