Announcement Announcement Module
Collapse
No announcement yet.
i used jdbcTemplate access database Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • i used jdbcTemplate access database

    i has a problem:
    sql statement:
    SELECT COUNT(*) FROM angle_dispatchemployee d INNER JOIN angle_comtract c ON d.deid=c.dispatchemployee_deid WHERE c.rstate=? AND d.state=? AND c.company_acid IN (?)

    In queryForInt parameter args, I have the how to write the parameters in brackets. If it is an array, like this:[1,2,3,4]

    If you do not look to understand:
    SELECT COUNT(*) FROM angle_dispatchemployee d INNER JOIN angle_comtract c ON d.deid=c.dispatchemployee_deid WHERE c.rstate=0 AND d.state=0 AND c.company_acid IN (1,2,3,4)

    queryForInt(sql,new object[]{0,0,?})

  • #2
    Who can help me?

    Comment


    • #3
      "IN" clauses need explicit placeholders

      Your SQL needs to look like this; all I did was add one "?" placeholder for each element of the "IN" clause:

      Code:
      SELECT COUNT(*)
      FROM angle_dispatchemployee d
      INNER JOIN angle_comtract c ON d.deid=c.dispatchemployee_deid
      WHERE c.rstate=?
        AND d.state=?
        AND c.company_acid IN (?, ?, ?, ?)
      ... and then your Java will look like this (assuming Java 1.5 or later):

      Code:
      String sql = ...;
      int count = jdbcOperations.queryForInt(sql, new Object[] {0, 0, 1, 2, 3, 4});
      In Spring 3.0 you can use varargs instead:

      Code:
      int count = jdbcOperations.queryForInt(sql, 0, 0, 1, 2, 3, 4);
      Hope this helps!

      Comment


      • #4
        Originally posted by andrews View Post
        ...[/CODE]Hope this helps!
        thank andrews very much.I would like to have a better answer

        Comment

        Working...
        X