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 8827607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:24:44+00:00 2026-06-14T07:24:44+00:00

I have code to retrieve a database item and it displays that in a

  • 0

I have code to retrieve a database item and it displays that in a mobile application using J2ME. I also use JSP for this so that my mobile app can get information from this.

I want to know how I can retrieve multiple items??

JavaBean:

public String doQuery() throws ClassNotFoundException, SQLException {
     //register driver
    DriverManager.registerDriver(new com.mysql.jdbc.Driver());

     //establish connection
    Conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/a1electric?user=root&password=raam030");

     //Create a Statement object from the Connection
    Statement stmt = Conn.createStatement();

    String sql = "SELECT JobID FROM employee WHERE employeeID=" +this.jobID;
    ResultSet rs = stmt.executeQuery(sql);
    String rt = "";
    rs.next();
    rt =  rs.getString("JobID");
    Conn.close();
    return rt;
   }

JSP Page:

  <jsp:useBean id="bean0" scope="session" class="data.queryBean"/>
<jsp:setProperty name="bean0" property="jobID" param="jobID"/>
<%= bean0.doQuery() %>

I would like to retrieve all the job IDs for this employee ID and display it.

  • 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-14T07:24:45+00:00Added an answer on June 14, 2026 at 7:24 am

    If there are multiple JobIDs for a given EmployeeID, then your result set has all those items and you should browse through the resultset:

    String sql = "SELECT JobID FROM employee WHERE employeeID=" +this.jobID;
    ResultSet rs = stmt.executeQuery(sql);
    List<String> jobIds = new ArrayList<String>();
    while (rs.next()) {
        jobIds.add(rs.getString("JobID"));
    }
    

    On a related note, you should

    1. try to use a connection pool (apache DBCP), instead of registering the driver and connecting to the DB everytime.
    2. use PreparedStatement to avoid potential SQL injection attacks:

      PreparedStatement stmt = con.prepareStatement(
          "SELECT JobID FROM employee WHERE employeeID= ?");
      stmt.setInt(1, this.jobID);
      ResultSet rs = stmt.executeQuery();
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code, which helps me to retrieve all table fields and associate
i have this code here which permits me to retrieve some dates. I have
I was using the following code to retrieve HTML snippets from a database table
I have a model like this: class Item(models.Model): code = models.CharField(max_length=200, unique=True) barcode =
I have code to retrieve data from a database into a form but it
I have some code that utilizes simplexml to retrieve some data. I perform about
In a C++ application that can use just about any relational database, what would
I have implemented a Phonegap application for iPhone using jQuery mobile . I have
I have code to retrieve stomp messages, which works. I then want to grab
I have a grid view and I add columns to it by code: //Retrieve

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.