0

Is it possible to get complete query from prepare statement object.

PreparedStatement stmt = null;

    try
    {
        stmt = connection.prepareStatement("insert into xyz(col1, col2)values(?, ?)");
        CourseFeedbackSettings feedbackSettings = course.getFeedbackSettings();

        stmt.setString      (1, "vinay");
        stmt.setString      (2, "sharma");
    }

now i want to get complete query form stmt like as follows: insert into xyz(col1, col2)values('vinay', 'sharma'); is it possible. If yes then how it is possible in J2EE.

Vinay Sharma
  • 1,163
  • 1
  • 10
  • 20
  • possible duplicate of [Get query from java.sql.PreparedStatement](http://stackoverflow.com/questions/2683214/get-query-from-java-sql-preparedstatement) – Semih Eker Dec 06 '14 at 13:44
  • yes you are there. Why are you not calling executeUpdate? any issues and did you tried that? – SMA Dec 06 '14 at 13:46
  • yes it giving me null pointer exception – Vinay Sharma Dec 06 '14 at 13:48
  • if i try system.outprintln(stmt) it gives me query with ? not with values – Vinay Sharma Dec 06 '14 at 13:48
  • For the PostgreSQL 8.x and MySQL 5.x JDBC drivers, yes it gives. For the case your JDBC driver doesn't support it, you can use a statement wrapper which logs all setter methods and finally populates a SQL string on toString() based on the logged information. – Semih Eker Dec 06 '14 at 13:51
  • internally println method execute toString() method on object if parameter is not a string object – Vinay Sharma Dec 06 '14 at 13:56
  • you know prepare statement having both query and parameter which will replaced at the time of execution, so i think there should be a way to get complete query what is going to execute on database. i think, what you say ? – Vinay Sharma Dec 06 '14 at 14:02

0 Answers0