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

  • Home
  • SEARCH
  • 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 8707159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:48:00+00:00 2026-06-13T03:48:00+00:00

I have a database with tables and values. I want to fetch that data

  • 0

I have a database with tables and values. I want to fetch that data and display it in jsp page. Don’t want to write query in jsp page, separate java class,creating java object values and then displaying it in select field in jsp. please help me…

here is my java class
p

ublic class EmpBean {
                    public java.util.List dataList(){
                        ArrayList list=new ArrayList();
                        try{
                             Class.forName("driver");
                                   Connection con = DriverManager.getConnection("url", "user", "pwd");
                                   Statement st=con.createStatement();
                                   System.out.println("hiiiii");
                                   ResultSet rs=st.executeQuery("select * from employee");
                                   while(rs.next()){
                                       list.add(rs.getString("name"));
                                       list.add(rs.getString("address"));
                                       list.add(rs.getString("contactNo"));
                                       list.add(rs.getString("email"));


                        }
                                   System.out.println(rs.getString("contactNo"));
                        }
                        catch(Exception e){}
                        return   list;

                        }

                }

//and my jsp file
                <%@page language="java" import="java.util.*" %>
                <html>
                <body> 
                <table border="1" width="303">
                <tr>
                <td width="119"><b>Name</b></td>

                </tr>
                <%Iterator itr;%>
                <%EmpBean p = new EmpBean();
                List list= (List) p.dataList(); %>
                for (itr=list.iterator(); itr.hasNext(); ){
                %>
                <tr>
                <select name="" id="" style="width: 150px;"">
                                <option value="-1"><%=itr.next()%></option>
                </select>

                </tr>
                <%}%>
                </table>
                </body>
                </html>
  • 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-13T03:48:01+00:00Added an answer on June 13, 2026 at 3:48 am

    i think you should try this

        public class EmpBean {
                    public java.util.List dataList(){
                        ArrayList list=new ArrayList();
                        try{
                             Class.forName("driver");
                                   Connection con = DriverManager.getConnection("url", "user", "pwd");
                                   Statement st=con.createStatement();
                                   System.out.println("hiiiii");
                                   ResultSet rs=st.executeQuery("select * from employee");
                                   while(rs.next()){
                                       list.add(rs.getString("name"));
                                       list.add(rs.getString("address"));
                                       list.add(rs.getString("contactNo"));
                                       list.add(rs.getString("email"));
    
    
                        }
                                   System.out.println(rs.getString("contactNo"));
                        }
                        catch(Exception e){}
                        return   list;
    
                        }
    
                }
    

    Assuming this class working fine and it is returning list with some value

    now on your jsp page

               <%@page language="java" import="java.util.*" %>
                <html>
                <body> 
                <table border="1" width="303">
                <tr>
                <td width="119"><b>Name</b></td>
    
                </tr>
                <%
                      ArrayList list;
                      EmpBean emp = new EmpBean();
                      list = emp.dataList();
                      ArrayList li = (ArrayList) li.get(0);
    
                %>
                <tr>
                <select name="" id="" style="width: 150px;"">
                                <option value="-1"><%=li.get(1)%></option>
                </select>
    
                </tr>
    
                </table>
                </body>
                </html>
    

    just check this code…it might happen that values fetched may be wrong here just check the values by changing list indexing and also if you can surround the whole scriptlets thing with try catch so that if exception occurs it will be easy to find bug…good luck and don’t worry if it doesn’t works i will give you sample code for sure i am using this code my project

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

Sidebar

Related Questions

I have a database that have two tables. The sql query fetching data correctly.
I have database, and in one the tables I need change the values of
I have two tables users registered_members I want to confirm values from user table
I am trying to fetch data from my database and when I display it
I have a page with a dynamic table, filled with data from mysql database.
I am doing a program involving a database. I have a query that will
I have a table in my database. I want to get the maximum value
I have a database table full of time points and experimental values at those
i have a large mysql database table in which one column contains values ranging
I Have a database called 'lms' with two tables loan and value, table loan

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.