2

What's the best way to store data retrieved from database in to Java for processing?

Here's some context:

Every month, data from Excel files are stored in the database and our web application (plain JSP/Servlet) does some processing on those data in the database. Currently we use an ArrayList of Hashmaps to store data retrieved from the tables but it seems very clunky. Is there a better way or data structure to do this?

It's not really possible to create some sort of a Model class for each of these because there's no logical "User" object or anything like that. It's basically chunks of random data that need to be processed. Stored procedure is not an answer as well because the processing logic is quite complicated.

2 Answers 2

2

Try using Java API's to get faster execution.

  1. Apache POI
  2. Java Excel API namely JXL

Check the link of sample tutorial using JXL: Link

If your excel files are in csv format then use openCSV.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, but the files HAVE to go to the database. We already use JXL to deal with the Excel files and insert them to the database.
1

It's not really possible to create some sort of a Model class for each of these because there's no logical "User" object or anything like that. It's basically chunks of random data that need to be processed. Stored procedure is not an answer as well because the processing logic is quite complicated.

Then there is not really a better way than using a List<Map<String, Object>>. To soften the pain, you could abstract the Map<String, Object> away by extending it to another class e.g. Row with eventually convenience methods to cast the values (.getAsDouble(columnname) or even T get(columnname, Class<T> type), etc) so that it makes traversing and manipulating less scary.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.