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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:40:36+00:00 2026-05-16T07:40:36+00:00

Here, i have coded to get data from DB. I want to store the

  • 0

Here, i have coded to get data from DB. I want to store the data in Object Array(POJO).
How to do it?
This code can also insert Data into DB, but omit it.

import java.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Jdbc {
static int id[] = new int[10];
static String name[] = new String[10];
static int salary[] = new int[10];
public static void main(String arg[])
{
    try {
          Statement stmt;
          ResultSet rs;
          Class.forName("com.mysql.jdbc.Driver");
          String url ="jdbc:mysql://localhost:3306/dwr";
          Connection con = DriverManager.getConnection(url,"root", "1234");
          System.out.println("URL: " + url);
          System.out.println("Connection: " + con);
          stmt = con.createStatement();
          System.out.println("Enter EmpId:");
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          int empId=Integer.parseInt(br.readLine());
          System.out.println("Enter Name:");
          BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
          String name1=br1.readLine();
          System.out.println("Enter Salary:");
          BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
          int salary1=Integer.parseInt(br2.readLine());
          stmt.executeUpdate("INSERT INTO employee set EmpId='"+empId+"', Name='"+name1+"', salary='"+salary1+"';");
          stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
          rs = stmt.executeQuery("SELECT * " + "from employee ORDER BY EmpId");
          System.out.println("Display all results:");
          int i = 0;
          while(rs.next()){
            id[i]= rs.getInt("Empid");
            name[i]= rs.getString("Name");
            salary[i]= rs.getInt("Salary");
            System.out.println("\n EmpId " + id[i]+ "\n name " + name[i] + "\n salary " + salary[i]);
          }

    }catch( Exception e ) {
          e.printStackTrace();
}
    Jdbc pojo = new Jdbc();

}
}
  • 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-05-16T07:40:37+00:00Added an answer on May 16, 2026 at 7:40 am

    You can either use the get methods provided to populate the fields of the object one at a time, so if you have an object named employee, that takes in 3 arguments (id, name and salary), you can have something like this:

    List<Employee> employee = new ArrayList<Employee>();
    while(rs.next())
    {
    employee.add(new Employee(rs.getInt("Empid"), rs.getString("Name"),rs.getInt("Salary"));
    }
    

    Or else, you can use an ORM Tools, like Hibernate and use it to retrieve objects as shown here

    P.S. The Java code I have provided is more like Pseudo code. I have not tested it.

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

Sidebar

Related Questions

I have googled and searched this site, but nothing specific appears and cannot get
Could someone help me figure out what this C++ code does I got it
I am making a program that reads and stores data from Windows EventLog files
I'm developping an Adobe AIR application which gathers data (from intranet webservices) and stores
Currently I want to optimize my 3d engine for consoles a bit. More precisely
I'm creating a product listing for an online store. It's pretty standard stuff, a
It's a pretty standard setup, WinForms client > Self-serving Business/Data layer > SQL Server
i am using a viewholder to display from a dynamic arrayadapter.it works but the
I have a problem with an MVC view that I just cannot seem to
How would you structure a large project with most of the business logic already

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.