I search the messages, but didn't find the answer here. Don't have the same
problem with Sun's J2EE reference platform.
>From a session bean I use an entity bean to create a database record. I
wrote a short program which creates one record. After the program ends, I
don't find the record by directly accessing the database ( SELECT * FROM
... ). However, when the program is run twice, it correctly refuses
creation at the second time, because the primary key is not unique.
I tried commit option A and B, though that shouldn't be the problem.
I close the PreparedStatement and the database connection after the call.
This is the related code:
public void setEntityContext(EntityContext context)
throws javax.ejb.EJBException, java.rmi.RemoteException {
m_context = context;
try {
InitialContext initial = new InitialContext();
m_ds = (DataSource) initial.lookup( dbName );
} catch( NamingException xn ) {
m_ds = null;
}
}
private void makeConnection() throws SQLException {
m_con = m_ds.getConnection();
}
private void closeConnection(){
System.out.println( "CB.closeConnection()" );
if ( m_con != null ){
try {
m_con.close();
} catch( Exception x ){ m_con = null; }
}
}
public String ejbCreate( ConferenceData cd ) throws CreateException {
try {
makeConnection();
insertRow( cd.topic, cd.id, .... );
} catch( Exception x ) {
throw new EJBException( "ConfB.ejbCreate(CD): " + x );
}
finally {
closeConnection();
}
id = cd.id; // pk
topic = cd.topic;
....
return id;
}
private void insertRow( String topic, String id, .... ) throws SQLException
{
System.out.println( "CB.insertRow() - enter" );
PreparedStatement pstmt = null;
String insertStatement =
"INSERT INTO conference( topic, id, startTimeS, duration, " +
"moderator, modPasswd, modGroupPasswd, generalPasswd, " +
"hasWhiteboard, hasSlideScreen, hasTextChat, hasVoiceChat, " +
"status, type, creatorID, createTime, billingID ) " +
"VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
try {
pstmt = m_con.prepareStatement( insertStatement );
pstmt.setString( 1, topic );
pstmt.setString( 2, id );
....
pstmt.executeUpdate();
} catch( SQLException xs ){
throw new SQLException( "CB.insertRow(): " + xs );
}
finally {
if ( pstmt != null ) {
try {
pstmt.close();
} catch( Exception x ) { pstmt = null; }
}
}
}
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user