Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is resultSet need to be synchronized in a web environment

Status
Not open for further replies.

outis

Programmer
Jun 20, 2001
21
MX
Hi, all, i need to put a web application stable and
i found that all the query follows the same structure:

public synchronized Vector getProfile(Integer profileId) throws SQLException {
try {
conn = con.getConnection();
pstmt = conn.prepareStatement("select...
while (rs.next()) {
// ADD DATA IN A VECTOR
}
} catch (SQLException e) {
finally{
// close resources
}
return vector;
}

I need to know if the reserved word is necessary when i
retrieve data from a DataBase. And if they are one of posibles causes of my application crash down

I will apreciate your comments.


 
No. JDBC does not require this, but whoever wrote the code may have used synchronized to work around an idiosyncracy in the driver. The ODBC-JDBC Bridge Driver used in conjunction with MS Access comes to mind.

One observation is that you are adding data to a Vector, which is synchronized, as opposed to ArrayList, which is not.

If this code is scattered through out the app, consider a utility or super class impl that would centralize the jdbc code, that way testing it would be a matter of changing one method.

By the way, what object is con? Or, more to the point, how do manage your connections? You should consider using a DataSource if you aren't doing so now. Post more of the class and db config.
 
I use a connection pool as attribute of class

private static oracle.jdbc.pool.OracleConnectionCacheImpl con;
an then I call the following method in the constructor

public static void createConnectionPool() throws SQLException {
try {
con = new OracleConnectionCacheImpl();
con.setDriverType(driverType);
con.setUser(user);
con.setPassword(password);
con.setServerName(serverName);
con.setDatabaseName(databaseName);
con.setNetworkProtocol(networkProtocol);
con.setPortNumber(portNumber);
con.setMinLimit(minLimit);
con.setMaxLimit(maxLimit);
con.setCacheScheme(con.FIXED_WAIT_SCHEME);
System.out.println("ConnectionPoolOracle created...");

} catch (SQLException e) {
e.printStackTrace();
throw new SQLException("Failed connection to database");
}
}
I use this class to manage all the bussines logic.
so I have all the methods declared in this class.
 
Do you have an error log or stack trace when the application
crashes?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top