A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/jdbc_innerjoin.htm below:

How to join contents of more than one table & display in Java

How to join contents of more than one table & display in Java Problem Description

How to join contents of more than one table & display?

Solution

Following example uses inner join sql command to combine data from two tables. To display the contents of the table getString() method of resultset is used.

import java.sql.*;

public class jdbcConn {
   public static void main(String[] args) throws Exception {
      Class.forName("org.apache.derby.jdbc.ClientDriver");
      Connection con = DriverManager.getConnection (
         "jdbc:derby://localhost:1527/testDb","username", "password");
      
      Statement stmt = con.createStatement();
      String query ="SELECT fname,lname,isbn from author inner join books on author.AUTHORID = books.AUTHORID";
      ResultSet rs = stmt.executeQuery(query);
      System.out.println("Fname  Lname   ISBN");
      
      while (rs.next()) {
         String fname = rs.getString("fname");
         String lname = rs.getString("lname");
         int isbn = rs.getInt("isbn");
         System.out.println(fname + "  " + lname+"   "+isbn);
      }
      System.out.println();
      System.out.println();
   }
}
Result

The above code sample will produce the following result. The result may vary.

Fname  Lname   ISBN
john  grisham   123
jeffry  archer   113
jeffry  archer   112
jeffry  archer   122

java_jdbc.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4