View Sql string in PreparedStatement
I am using PreparedStatement to update a table. In the debug phase, I want to see the sql statement string, does anyone know how I am able to see the sql string? That is, in below ***** area, what should I add to show the sql statement ? Thanks in advance.
A sample code below:
.......
PreparedStatement update = conn.prepareStatement
(
"UPDATE link_store SET STORE_NAME = ?, IS_ACTIVE_STORE = ?, " +
"HAS_PRODUCT = ?, MARKETER_ID = ?, PRODUCT_PAGESIZE = ?, "+
"STORE_DESC = ?, REASON_INACTIVE = ?, S_LOGO = ?, "+
"store_long_desc = ? "+
"WHERE STORE_ID = ?"
);
try
{
populate(update, store);
update.setString(10, store.getStoreId());
// *********
if (update.executeUpdate()!= 1)
{
thrownew EntityNotFoundException(
"Store " + store.getStoreId() +" not found");
}
}catch (SQLException e)
{
if (InvalidFieldException.SQL_STATE.equals(e.getSQLState()))
{
thrownew InvalidFieldException(e);
}else
{
throw e;
}
}finally
{
update.close();
}
.....
privatevoid populate(PreparedStatement stmt, Store store)
throws SQLException
{
stmt.setString(1, store.getStoreName());
if (store.getIsActiveStore())
{
stmt.setInt(2, 1);
}
else
{
stmt.setInt(2, 0);
}
if (store.getHasProd())
{
stmt.setInt(3, 1);
}
else
{
stmt.setInt(3, 0);
}
stmt.setInt(4, store.getMarketer().getMarketerId());
stmt.setInt(5, store.getProdPageSize());
stmt.setString(6, store.getStoreDescShort());
stmt.setString(7, store.getReasonInactive());
stmt.setString(8, store.getStoreLogoName());
stmt.setString(9, store.getStoreDescLong());
}

