Krystian
Krystian

Reputation: 1026

Insert and check data in PostgreSql database

I have the following problem. Using Java application i need to insert data from external XML file to database table every 1 second.

In addition, I have to perform a select/update query on the same table.

Table is cleaned every few days. My question is: how to solve it optimally? Everything must work live. We can't allow a situation where there is a time shift( records are not checked every 1s).

Any ideas?

Upvotes: 0

Views: 2249

Answers (2)

Guillaume Polet
Guillaume Polet

Reputation: 47608

Depending on how complex you plan your application to be, you might consider JPA/Hibernate to access your database. It makes a lot simpler to access your DB (because you manipulate POJO's to access your data) but the downside is that it is not optimal in term of performance (manipulating raw sql and raw data will always be faster than manipulating objects).

For your job check, I would set up quartz which will offer you the possibility to schedule jobs periodically.

Your question is kind of vague to give more hints. Is it a web application? a Java EE one? A heavy-client? How bad do you need high-performance? Do you want to create a small-application with no future written on a pizza-napkin or do you plan to have an application that will extend in the future.

Upvotes: 1

bpgergo
bpgergo

Reputation: 16037

10-20 records per second is not a large amount. Anyway, if you have any performance problem, make sure you use JDBC batch inserts:

PreparedStatement stmt = con.prepareStatement(
    "INSERT INTO table_name (field_name1, field_name2) VALUES (?, ?)");

stmt.setInt(1, 2000);
stmt.setString(2, "String value");
stmt.addBatch();

stmt.setInt(1, 3000);
stmt.setString(2, "Other String");
stmt.addBatch();

// submit the batch for execution
int[] insertCounts = stmt.executeBatch();

Upvotes: 0

Related Questions