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());

}

[3257 byte] By [northclouda] at [2007-11-27 11:58:56]
# 1

In general you can't.

Some drivers support a method that allow you to see that. You can dig through the JDBC API to find it. And if your driver doesn't support it then you are out of luck.

You can create/find a proxy driver. It just passes through values to the actual driver and retains the values. To my mind that isn't really the same thing however.

Myself I just print the sql string and the parameters.

(As as stylistic convention I format my statements with the '+' at the beginning of the line and the space as well. It makes it more obvious when viewing.)

jschella at 2007-7-29 19:22:46 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...