2
I am saving a feature for time-consuming processing and must return your ID so the user can check its status in the future.
The idea is that the user insert a set of data for import (for simplicity, let’s assume it is a string) and that it can query whether this import is waiting, in processing, has been successful or failed.
The idea is to insert a data in the following table:
CREATE TABLE importacao (
id_importacao INTEGER PRIMARY KEY AUTOINCREMENT,
data_inicio DATETIME NOT NULL,
estado STRING NOT NULL,
dados STRING NOT NULL
)
public int iniciarImportacao(String conjuntoDados) throws SQLException {
try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO importacao (data_inicio, estado, dados) VALUES (DATETIME('now'), 'ESPERANDO', ?)")) {
pstmt.setString(1, conjuntoDados);
pstmt.executeUpdate();
int idImportacao = // resultado na coluna id_importacao
jogarThreadWorkerImportacao(idImportacao);
return idImportacao;
}
}
At worst I know I could make a single consultation SELECT last_insert_rowid()
, but there is another more JDBC alternative to getting that result?
I’m leaving without the tag sqlite because it is a detail in the query, the focus should even be the use of JDBC for such an order.
The same focus is pure JDBC, but
JdbcTemplate
and its Spring variants are welcome as a response complement.MyBatis
andHibernate
are also welcome, but are more secondary to me– Jefferson Quesado