I need an advice about the counter of incoming requests for Java ejb web service. Application server where a web service is deployed has 4 nodes, so the incoming request can be processed on any of 4, and I decided to store counter value in Oracle database.
I set the current number of request by calling select SEQPACKSCYCLETOT.NEXTVAL from dual
and it works fine.
But I also need to show current counter value, and here is a problem. When I call select SEQPACKSCYCLETOT.CURRVAL from dual
sometimes I get an exception sequence SEQPACKSCYCLETOT.CURRVAL is not yet defined in this session
.
What session is it about and how to work with it? Here is the code snippet:
@Singleton
public class DbWorkerImpl implements DbWorker {
@Override
public Long getPacksTotSeqValue() throws SQLException {
String query = "select SEQPACKSCYCLETOT.CURRVAL from dual";
Long packetsCount = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection(Username, Password);
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
if (rs.next())
packetsCount = rs.getLong(1);
}
catch (SQLException e) {
logS.debug(this.servername + e.getMessage());
}
finally{
if (rs!=null) rs.close();
if (stmt!=null) stmt.close();
if (conn!=null) conn.close();
}
return packetsCount;
}