Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see what my PreparedStatement looks like? [duplicate]

Possible Duplicate:
How can I get the SQL of a PreparedStatement?

I make a PreparedStatement (PS) and run some setString(int a,String b) on it. After this, how do I see what my PS finally looks like ?

like image 392
sweet dreams Avatar asked Oct 08 '22 02:10

sweet dreams


1 Answers

If I understand you, you'd want someting like:

    PreparedStatement pstmt = 
           connection.prepareStatement("insert into table tab(col) values(?)");
    pstmt.setString(1, "my string value");

and then you want to see a string like:

"insert into table(col) values('my string value')"

Did I get your meaning right?

If so, I think you can't do that. I think the statement is precompiled without parameter values, and these are kept separately, so you can reuse the statement with different parameters.

What you can do, is to retrieve parameter metadata, like this:

    ParameterMetaData pmd = pstmt.getParameterMetaData();

And then call stuff like:

    pmd.getParameterCount();
    pmd.getParameterClassName(1);
    pmd.getParameterType(1);
like image 178
pafau k. Avatar answered Oct 18 '22 09:10

pafau k.