Results 1 to 2 of 2
  1. #1
    kishan.java is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Red face how to get data from more than two tables based on other

    Hi All,

    I am new to java.

    I want to get the data from 3 table.

    first i will use a query on both table . after getting the result set. i want to write on more query inside the result set with where clause .

    so that i will get only corresponding match records from third table in the result set.

    please let me know how to write the code.

    my code is as below:


    try{

    String sql = "select DISTINCT REQUISITIONS.FOLDERID, REQUISITIONS.AUTOREQ, REQUISITIONS.MANAGERID, REQUISITIONS.RECRUITERID, " +
    " REQUISITIONRESPONSE.FOLDERID, REQUISITIONRESPONSE.QUESTION_TYPE_ID, REQUISITIONRESPONSE.RESPONSE " +
    " from REQUISITIONS,REQUISITIONRESPONSE" +
    " where REQUISITIONS.FOLDERID=REQUISITIONRESPONSE.FOLDERID ";



    System.out.println(":kishan test data1 " );



    ResultSet rs1 = st.executeQuery(sql);

    while(rs1.next())
    {
    System.out.println(":kishan test data2 " );

    int aInt = Integer.parseInt(rs1.getString(1));


    Candidate candidate=new Candidate();
    candidate.setRsKey(+aInt);

    candidate.setEmail(rs1.getString(2));
    candidate.setName(rs1.getString(3));
    candidate.setPhone(rs1.getString(4));

    candidate.setDegree(rs1.getString(5));
    candidate.setGradyear(rs1.getString(6));
    candidate.setSchoolname(rs1.getString(7));

    String sql1 = "select QUESTION_TYPE_ID, QUESTION_DESC from QUESTION_TYPE where QUESTION_TYPE_ID='"+rs1.getString(6)+"'";
    ResultSet rs2 = st.executeQuery(sql1);

    while(rs2.next())
    {

    System.out.println(":kishan test data in second query " +rs2.getString(1));
    if (rs2.getString(2).equals("Cost Center")){

    candidate.setJobtitle(rs1.getString(7));
    }else if (rs2.getString(2).equals("Business Unit")){
    candidate.setOrgname(rs1.getString(7));
    }



    }


    list.add(candidate);
    }

    }

    Here i am getting Exhuasted Result set exception.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

Similar Threads

  1. Replies: 1
    Last Post: 01-31-2011, 02:38 AM
  2. Displaying Multiple Tables based on Input
    By Berzerk in forum New To Java
    Replies: 11
    Last Post: 06-17-2010, 07:54 AM
  3. Replies: 1
    Last Post: 05-20-2010, 03:27 PM
  4. How to use one form to submit data to 2 tables on mysql
    By kwesiaryee in forum New To Java
    Replies: 2
    Last Post: 10-10-2008, 01:41 PM
  5. Replies: 0
    Last Post: 12-24-2007, 09:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •