I have a question when I put the result value of the ResultSet in the list while using JDBC

Asked 2 years ago, Updated 2 years ago, 121 views

I'd like to put the result value of ResultSet in VO format on the list called allEmployee.

The values in the list index should be different, so I'm continuing to create instances.

Wouldn't this be a performance problem if the amount of data increased?

preparedStatement = connection.prepareStatement(sql.toString().toUpperCase());
resultSet = preparedStatement.executeQuery();

while (resultSet.next()){
    employee = new Employee();
    employee.setEmpid(resultSet.getInt("empid"));
    employee.setName(resultSet.getString("name"));
    allEmployee.add(employee);
}            

The goal is to return a list of VO's. I'd appreciate it if you let me know if there's a better way~

jdbc resultset

2022-09-22 21:16

1 Answers

As long as you get all (or so much) data in the table More data can actually cause problems.

If the above is a single user, it may not be a big problem. (Even if you handle millions of cases, you may not experience any problems other than slowing down.)

However, if it is a form of service for a large number of users, such as the web, This can be a problem depending on the amount of simultaneous access to the above logic.

Basically, each time you create a Java object, it consumes heap memory that Java can use, which can cause frequent garbage collections to save memory, which can degrade performance.

If you're aiming for a real service, we recommend that you design it to reduce the amount that you need to get once and switch to VO as much as possible.

Note. The above method is not wrong, but a method that is used a lot. Depending on how you write SQL query statements, performance is often highly affected.


2022-09-22 21:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.