I am restricted in how I do this.
Because I have to access a legacy file on the iSeries which is populated
every night with unique numbers.
My question is basically what code do I need to test if the following
statement fails.
con.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
Even though I would of expected this to of been picked up by the
}catch (SQLException e){
used in the try block.
Appreciate any help.
Re: Locking of record using SQL in JAVA Websphere application.
Joe Sam Shirah
to:
java400-l
09/10/2012
20:49
Sent by:
java400-l-bounces@xxxxxxxxxxxx
Please respond to Java Programming on and around the IBM i
Obviously I don't know your app or requirements, but it's been my
experience over the years that DIY attempts at unique numbers from files or
tables almost always have issues.
I don't know if it would work in your case, but my suggestion would be
to use one or more dummy tables with identities ( auto-increment keys or
columns. ) The database handles the numbers and you are guaranteed they
are
unique.
HTH,
Joe Sam
Joe Sam Shirah - www.conceptgo.com (904) 302-6870
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum: www.ibm.com/developerworks/java
Just the JDBC FAQs: www.jguru.com/faq/JDBC
Going International? www.jguru.com/faq/I18N
Que Java400? www.jguru.com/faq/Java400
-----Original Message-----
From: mtodd@xxxxxxxxxxxx
Sent: Tuesday, October 09, 2012 8:43 AM
To: java400-l@xxxxxxxxxxxx
Subject: Locking of record using SQL in JAVA Websphere application.
Have Web app that reads record from iSeries to get a unique number, then
deletes that record.
Need to make sure that only one web user gets that unique number.
Application seems to work 99% of the time but sometimes log reports
duplicate key error message when using
unique number to write to transaction file. This seems to suggest that
more than one user retrieved the
unique number.
I use SQL to access the iSeries, setting the connection to
TRANSACTION_SERIALIZABLE to lock the record.
Appreciate any help on this issue.
Many thanks.
Below is the code :
sqlSelect="SELECT AMMBR# FROM MBPRDDTA.MBAMBRP WHERE AMGRWS= ? FOR
UPDATE";
try{
con=AS400ConnectionManager.getInstance().getConnection();
con.setTransactionIsolation
(Connection.TRANSACTION_SERIALIZABLE);
psmt=con.prepareStatement(sqlSelect);
psmt.setString(1,memberData.getTradeIndividual());
ResultSet rs=psmt.executeQuery();
rs=psmt.executeQuery();
if(rs.next()){
response.setMemberNumber(rs.getLong("AMMBR#"));
if (deleteMemberNumber(response.getMemberNumber
(),con)){
response.setStatus
(ApplicationStatus.SUCCESS);
response.setMessage("Successfully retrieved &
deleted member number from MBAMBRP");
}
}
con.commit();
}catch (SQLException e){
response.setMessage("SQL exception : Error retrieving &
deleting member number from MBAMBRP");
e.printStackTrace();
} catch (PersistenceException e) {
response.setMessage("Persistence exception : Error
retrieving & deleting member number from MBAMBRP");
e.printStackTrace();
}
finally{
try {
psmt.close();
con.close();
} catch (SQLException e) {
response.setMessage("SQL final exception : Error
retrieving & deleting member number from MBAMBRP");
e.printStackTrace();
}
}
***********************************************************************************
CONFIDENTIALITY / DISCLAIMER NOTICE
This communication contains information which is confidential and may also
be privileged.
It is for the exclusive use of the recipient(s). If you are not the
intended recipient(s)
please note that any distribution, copying or use of this communication or
the information
in it is strictly prohibited.
Any views or opinions presented are solely those of the author and do not
necessarily
represent those of Costco Wholesale UK Ltd. If you have received this
communication in
error please notify us by e-mailing the author or by telephoning (01923
213113) and then
delete the communication and any copies of it.
This communication is from Costco Wholesale UK Ltd whose registered office
is at UK Home Office,
Hartspring Lane, Watford WD25 8JS, England.
***********************************************************************************
--
This is the Java Programming on and around the IBM i (JAVA400-L) mailing
list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/java400-l.
***********************************************************************************
CONFIDENTIALITY / DISCLAIMER NOTICE
This communication contains information which is confidential and may also be privileged.
It is for the exclusive use of the recipient(s). If you are not the intended recipient(s)
please note that any distribution, copying or use of this communication or the information
in it is strictly prohibited.
Any views or opinions presented are solely those of the author and do not necessarily
represent those of Costco Wholesale UK Ltd. If you have received this communication in
error please notify us by e-mailing the author or by telephoning (01923 213113) and then
delete the communication and any copies of it.
This communication is from Costco Wholesale UK Ltd whose registered office is at UK Home Office,
Hartspring Lane, Watford WD25 8JS, England.
***********************************************************************************
As an Amazon Associate we earn from qualifying purchases.