I follow JBoss documentation and setup JBoss 2.4.1 and SQLServerPool (see below). In ejb-jar.xml, I set the value of trans-attribute to "Required". When I run the java code (see below), it seems that the record is inserted successfully. However, when I open the table and the record is not there. Thus, I think the transaction is not committed when the connection is closed (see the JBoss log below). What do I need to do to set the database tranaction right? Please help. Thanks.
SQLServerPool setup:
org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl
SQLServerPool
jdbc:odbc:odbcname
username
password
true
TRANSACTION_SERIALIZABLE
Java Code:
public boolean insertData() { boolean isInserted = true; Connection conn = null; Statement stmt = null; try { InitialContext context = new InitialContext(); DataSource ds = (DataSource) context.lookup("java:/SQLServerPool"); conn = ds.getConnection(); stmt = conn.createStatement(); String sqlString = "insert into staff(firstname, lastname) values ('Jason', 'Smith')"; int status = stmt.executeUpdate(sqlString); System.out.println(status); } catch (NamingException ex) { System.out.println("NamingException caught when trying to get data source from JNDI"); ex.printStackTrace(); isInserted = false; } catch (SQLException ex) { ex.printStackTrace(); isInserted = false; } catch (Exception ex) { ex.printStackTrace(); isInserted = false; } finally { try { if (stmt!=null) stmt.close(); if (conn!=null) conn.close(); } catch (Exception ex) { ex.printStackTrace(); } } return isInserted; }