Posted By:
SMPS_SMPS
Posted On:
Sunday, February 17, 2002 11:06 PM
How to set Isolation Level in Entity Bean ( JoNas as Application Server, Postgres as Database) Trying to use Connection.setTransactionIsolation(Connection.TRANSACTION_SERILIZABLE) but getting Runtime Error. Code is as under : --------------------------------------------------------------------------- public eUserPK ejbCreate(String p_sUserID,String p_sFirstName,String p_sLastName,String p_sPassword,String p_sAddress1,String p_sAddress2,String p_sPhone1,String p_sPhone2,String p_sEmail,String p_sStatus,String p_sProjectPK) throws CreateException { Connection conn = null; try { conn = getConnection(); conn.setAutoCommit(false);
More>>
How to set Isolation Level in Entity Bean ( JoNas as Application Server, Postgres as Database)
Trying to use Connection.setTransactionIsolation(Connection.TRANSACTION_SERILIZABLE) but getting Runtime Error.
Code is as under :
---------------------------------------------------------------------------
public eUserPK ejbCreate(String p_sUserID,String p_sFirstName,String p_sLastName,String p_sPassword,String p_sAddress1,String p_sAddress2,String p_sPhone1,String p_sPhone2,String p_sEmail,String p_sStatus,String p_sProjectPK) throws CreateException {
Connection conn = null;
try {
conn = getConnection();
conn.setAutoCommit(false);
conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
}
catch (Exception e) {
e.printStackTrace();
}
int iUserPK = getNextPKFromSequence("users");
m_iPk = iUserPK;
m_sUserId = p_sUserID;
m_sFirstName = p_sFirstName;
m_sLastName = p_sLastName;
m_sPassword = p_sPassword;
m_sAddress1 = p_sAddress1;
m_sAddress2 = p_sAddress2;
m_sPhone1 = p_sPhone1;
m_sPhone2 = p_sPhone2;
m_sAdmin = "N";
m_sEmail = p_sEmail;
m_sStatus = p_sStatus;
Calendar calendar = Calendar.getInstance();
String sDay = String.valueOf(calendar.get(Calendar.DATE));
String sMonth = String.valueOf(calendar.get(Calendar.MONTH)+1);
String sYear = String.valueOf(calendar.get(Calendar.YEAR));
String sHour = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
String sMinute = String.valueOf(calendar.get(Calendar.MINUTE));
String sSecond = String.valueOf(calendar.get(Calendar.SECOND));
m_sCreatedDate = sYear + "-" + sMonth + "-" + sDay +" "+sHour+":"+sMinute+":"+sSecond;
PreparedStatement pstmtUsers = null;
// Create the primary key
eUserPK ebUserPK = new eUserPK(iUserPK);
try {
pstmtUsers = conn.prepareStatement("insert into users (pk, user_id,first_name,last_name,password,created_date,address1, address2,phone1,phone2,email_id,is_admin,is_active) values (?,?, ?, ?,?,?,?,?,?,?,?,?,?)");
pstmtUsers.setInt(1, m_iPk);
pstmtUsers.setString(2, m_sUserId);
pstmtUsers.setString(3, m_sFirstName);
pstmtUsers.setString(4, m_sLastName);
pstmtUsers.setString(5, m_sPassword);
pstmtUsers.setString(6, m_sCreatedDate);
pstmtUsers.setString(7, m_sAddress1);
pstmtUsers.setString(8, m_sAddress2);
pstmtUsers.setString(9, m_sPhone1);
pstmtUsers.setString(10, m_sPhone2);
pstmtUsers.setString(11, m_sEmail);
pstmtUsers.setString(12, m_sAdmin);
pstmtUsers.setString(13, m_sStatus);
pstmtUsers.executeUpdate();
}
catch (SQLException e) {
throw new CreateException("Failed to create bean in database :eUser");
}
finally {
try {
if(pstmtUsers != null) pstmtUsers.close();
if(conn != null) conn.close();
}
catch(SQLException se) {
se.printStackTrace();
}
}
// Return the primary key
return ebUserPK;
}
-----------------------------------------------------------------------------
Run time Error is as under :
java.sql.SQLException : Error : SET TRANSACTION ISOLATION LEVEL must be called before any query.
<<Less