Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:50:15+00:00 2026-06-15T08:50:15+00:00

i am fetching all data from database and stored the resultset to a list.

  • 0

i am fetching all data from database and stored the resultset to a list. but could not fetch all data. i want to store the data in a dropdownlist. My code is bellow.

public static void updateChallan(){
    ChallanNumber pd=null;
    int i=0;
    String customerName="";
    List<ChallanNumber> challanList= new ArrayList<ChallanNumber>();
    Connection con = DB.getConnection();
    try
    {
    String st="select CHALLAN_NUMBER,CUSTOMER_CODE,CHALLAN_DATE from DELIVERY_CHALLAN_DETAILS order by CHALLAN_NUMBER";
    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery(st);
    while(rs.next())
    {
        String stCustName="select CUSTOMER_NAME from CUSTOMER_DETAILS where CUSTOMER_CODE='"+rs.getString(2)+"'";
        Statement stmtCustName=con.createStatement();
        ResultSet rsCustName=stmtCustName.executeQuery(stCustName);
        while(rsCustName.next()){
            customerName=rsCustName.getString(1);
        }

        customerName=rsCustName.getString(1);
        //System.out.println(customerName +" "+i);
        pd=new ChallanNumber(rs.getString(1),customerName,rs.getString(3));
        challanList.add(i,pd);
        i++;
    }
    }
    catch(Exception e)
    {
        //e.printStackTrace();
    }
    render(challanList);
}

Dropdownlish code is in bellow.

<select name="challanNumber" id="challanNumber">
              <option value="selected" selected="selected">ChallanNumber-CustomerCode-    Date</option>

              #{list challanList, as:'cl'}

              <option value="${cl.challanNumber}">${cl.challanNumber}(${cl.customercode}-${cl.challanDate})</option>

                #{/list}



            </select>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:50:16+00:00Added an answer on June 15, 2026 at 8:50 am

    You need to close everything you open, it means statement, resultsets. You do that in the finally part of your try/catch to ensure things are correctly closed.

    When you close a statement, the resultset linked to that statement is closed too.

    public static void updateChallan() throws Exception {
        ChallanNumber pd = null;
        int i=0;
        String customerName = "";
        List<ChallanNumber> challanList= new ArrayList<ChallanNumber>();
        Connection con = DB.getConnection();
        Statement stmt = null;
        try {
            String st = "select CHALLAN_NUMBER,CUSTOMER_CODE,CHALLAN_DATE from DELIVERY_CHALLAN_DETAILS order by CHALLAN_NUMBER";
            stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(st);
            while (rs.next()) {
                String stCustName = "select CUSTOMER_NAME from CUSTOMER_DETAILS where CUSTOMER_CODE='" + rs.getString(2) + "'";
                Statement stmtCustName = con.createStatement();
                try {
                    ResultSet rsCustName = stmtCustName.executeQuery(stCustName);
                    while (rsCustName.next()){
                        customerName = rsCustName.getString(1);
                    }
                } finally {
                    if (stmtCustName != null) 
                        stmtCustName.close();
                }
    
                customerName = rsCustName.getString(1);
                //System.out.println(customerName +" "+i);
                pd = new ChallanNumber(rs.getString(1), customerName, rs.getString(3));
                challanList.add(i, pd);
                i++;
            }
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            if (stmt != null) 
                stmt.close();
        }
        render(challanList);
    }
    

    Besides, you should read the docs of PlayFramework (here for Play2) there are database stuff to avoid using ResultSets and Statements directly, dealing with higher structures like domain objects, the framework will do the rest for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now a lot of scripts to facebook-style fetching data from url, but all of
Fortunately, I know how to fetch data from the database, That's not a problem.
I'm fetching data from all 3 tables at once to avoid network latency. Fetching
Should application expect the unexpected when fetching data from database? Lets say that we
I'm fetching data from a MYSQL database I've created which stores a players statistics
i have echoed the data from database in another file.. now i am fetching
I am changing row background color if the fetching data from database size is
I am fetching some data from a database like this $sql =SELECT * FROM
I have an MS SQL Server 2008 Database, from which I am fetching data
Sometimes, when fetching data from the database either through the python shell or through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.