Re: Escaping Strings

Mark Matthews <[email protected]> Tue, 12 Jul 2016 22:03:50 -0500
Newsgroups gmane.comp.db.mysql.java
Message-ID <[email protected]>

On 07/12/2016 09:16 PM, Mark Matthews wrote:
>
>
>

Hi,

A couple of logical errors  (no compiler, didn't desk-check my code):

[snip]
>
>
>
>         if (conditions.size() > 0) {

Obviously:

               actualQuery.append(" WHERE ");

> boolean needsAnd = false;
>
>             for (Condition cond : conditions) {
>                 if (needsAnd) {
>                     actualQuery.append(" AND ");
>                 } else {
>                     needsAnd = true;
>                 }
>
>                 actualQuery.append(cond.leftHandSide);
>                 actualQuery.append(" ");
>                 actualQuery.append(cond.operator);
>                 actualQuery.append(" ? ");
>             }
>         }
>
>         // .. do ORDER BY in a similar fashion
>
>         String sql = actualQuery.toString();
>         PreparedStatement pStmt = connection.prepareStatement(sql);
>
>         if (conditions.size() > 0) {
>             int paramNum = 1; // JDBC starts numbering with 1
>
>             for (Condition cond : conditions) {
>                 pStmt.setObject(paramNum, cond.value);

and

                     paramNum++;


Regards,

    -Mark

-- 
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/java