Your question, your audience. Choose who sees your identity—and your question—with question security.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
In my struts action class, i get the datasource object with :
DataSource dataSource = getDataSource(request);
and then pass the datasource object to my Database Manager class.
For example :
PageDA pageDA = new PageDA();
pageDA.deletePage( dataSource, pageId );
in th PageDA class :
public boolean deletePage( DataSource dataSource , int pageId)
{
Connection myConnection = null;
PreparedStatement pstmt = null;
boolean returnB = false;
try
{
myConnection = dataSource.getConnection()
pstmt = myConnection.prepareStatem
pstmt.setInt( 1, pageId );
if( pstmt.executeUpdate() == 1 )
{
returnB = true;
}
if( !myConnection.getAutoCommi
{
myConnection.commit();
}
}
catch (SQLException sqle)
{
try
{
myConnection.rollback();
}catch(Exception e)
{
e.printStackTrace();
}
sqle.printStackTrace();
}
finally
{
try
{
if( pstmt != null ) pstmt.close();
if( myConnection != null ) myConnection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return ( returnB );
}
hth,
Kok Choon.