0

I'm new to Parameterized SQL, What I'm about doing is updating stuff with it, It's fine there, But i have a (log) table that holds that Parameterized SQL as Description of what happened, When i insert Parameterized SQL to log_table it keeps showing "?" this symbol

code to save log:

    PreparedStatement stat;
    ResultSet rs;
    String sql="insert into rozhanai_log values (null,?,?,?)";
    try
    {
        stat = conn.prepareStatement(sql);
        stat.setString(1,sqlParadanan);//(sqlParadanan) is my parameterized SQL String
        stat.setTimestamp(2,time);
        stat.setString(3,empName);
        stat.execute();
    } 
    catch (Exception e)
    {
        System.out.println("log Nabw");
        e.printStackTrace();
    }

and SQL String in (log) table shown like this:

update rozhanai_customer_account set rozhanai_money_balance = rozhanai_money_balance + 1000.0 where rozhanai_account_id=?

what can i do here?

i was thinking about something like (re-set the parameters)?

thanks

  • Yes, it will always show `?` for the parameters. Remember that JDBC does not "concatenate" the parameters as string values into the PreparedStatement. It performs a direct insertion of the value(s) in the database engine session according to the JDBC type. For example, `setTimestamp()` will send a bona fide timestamp value, not its string representation. – The Impaler Oct 12 '18 at 17:35
  • I would suggest rendering values themselves into strings and saving these strings instead of the SQL statement. Maybe in a CSV-like format. – The Impaler Oct 12 '18 at 17:37
  • @TheImpaler: that's not true for the Postgres JDBC driver. `PreparedStatement.toString()` will actually show the parameter values. –  Oct 12 '18 at 21:34
  • @a_horse_with_no_name this method works fine, thanks! – mhamad arsalan Oct 13 '18 at 10:32
  • @mhamadarsalan If it worked, please post it as an answer. It could be of use. – The Impaler Oct 13 '18 at 13:48

1 Answers1

0

thanks for a_horse_with_no_name for helping, simply with PreparedStatement.toString() can get SQL String without any ? symbol

    .
    .
    stat.setString(3,empName);
    String fullSQL = stat.toString();
    System.out.println(fullSQL); 
    .
    .
    .

output :

com.mysql.jdbc.JDBC4PreparedStatement@6b179d: insert into rozhanai_log values (null,update rozhanai_customer...,2018-05-23,'Hama')

thanks for you