Single quote instead of double? - Mailing list pgsql-jdbc

From Oguz Imre
Subject Single quote instead of double?
Date
Msg-id E0002D36-5713-11D7-94F9-003065A215CC@comcast.net
Whole thread Raw
Responses Re: Single quote instead of double?
Past Single quote instead of double? But there's more
List pgsql-jdbc
Gentle people,


When I run the following code, I get the resulting output which
PostgreSQL balks at. Is there a switch or something to yield single
quote? Kindly advise.


Code snippet: (from TableExample)


<fixed><color><param>0C0C,FFFF,3535</param>            String query =

                </color><color><param>F4F4,7979,9C9C</param>"update
site_sifre"</color><color><param>0C0C,FFFF,3535</param>+
//hard coded the tablename as String tableName =

                </color><color><param>F4F4,7979,9C9C</param>" set
"</color><color><param>0C0C,FFFF,3535</param>+columnName+</color><color><param>F4F4,7979,9C9C</param>"
= "</color><color><param>0C0C,FFFF,3535</param>+dbRepresentation(column,
value)+    //

</color><color><param>0C0B,FFFE,3534</param>metaData.getTableName(column</color><color><param>0000,0000,FFFE</param>+1</color><color><param>0C0B,FFFE,3534</param>);
returns "null"</color><color><param>0C0C,FFFF,3535</param>

                </color><color><param>F4F4,7979,9C9C</param>" where
"</color><color><param>0C0C,FFFF,3535</param>;

            </color><color><param>A5A5,1C1C,DCDC</param>// We don't
have a model of the schema so we don't know the</color><color><param>0C0C,FFFF,3535</param>

            </color><color><param>A5A5,1C1C,DCDC</param>// primary
keys or which columns to lock on. To demonstrate</color><color><param>0C0C,FFFF,3535</param>

            </color><color><param>A5A5,1C1C,DCDC</param>// that
editing is possible, we'll just lock on everything.</color><color><param>0C0C,FFFF,3535</param>



</color><color><param>FFFF,5E5E,CACA</param>for</color><color><param>0C0C,FFFF,3535</param>(</color><color><param>FFFF,5E5E,CACA</param>int</color><color><param>0C0C,FFFF,3535</param>
col =
</color><color><param>0000,0000,FFFF</param>0</color><color><param>0C0C,FFFF,3535</param>;
col<<getColumnCount(); col++) {

                String colName = getColumnName(col);


</color><color><param>FFFF,5E5E,CACA</param>if</color><color><param>0C0C,FFFF,3535</param>
(colName.equals(</color><color><param>F4F4,7979,9C9C</param>""</color><color><param>0C0C,FFFF,3535</param>)){ 


</color><color><param>FFFF,5E5E,CACA</param>continue</color><color><param>0C0C,FFFF,3535</param>;

                }


</color><color><param>FFFF,5E5E,CACA</param>if</color><color><param>0C0C,FFFF,3535</param> (col
!=
</color><color><param>0000,0000,FFFF</param>0</color><color><param>0C0C,FFFF,3535</param>) {

                    query = query +
</color><color><param>F4F4,7979,9C9C</param>" and
"</color><color><param>0C0C,FFFF,3535</param>;

                }

                query = query + colName
+</color><color><param>F4F4,7979,9C9C</param>" =
"</color><color><param>0C0C,FFFF,3535</param>+

                    dbRepresentation(col, getValueAt(row, col));

                            }

            System.out.println(query);


</color><color><param>A5A5,1C1C,DCDC</param>//System.out.println("Not
sending update to database");</color><color><param>0C0C,FFFF,3535</param>

            statement.executeQuery(query);

        }


</color><color><param>FFFF,5E5E,CACA</param>catch</color><color><param>0C0C,FFFF,3535</param> (SQLException
e) {

            e.printStackTrace();


System.err.println(</color><color><param>F4F4,7979,9C9C</param>"Update
failed"</color><color><param>0C0C,FFFF,3535</param>);

        }

        Vector dataRow = (Vector)rows.elementAt(row);

        dataRow.setElementAt(value, column);


    }


</color><color><param>00A2,0017,00EA</param>=====  OUTPUT ===

update site_sifre set username = "test this, too,again           "
where site_sifreid = "realOnePlayer            " and username = "test
this, too           " and sifre = "ssssssss       " and confirmdate =
"2003-03-14 19:18:50.319598"

java.sql.SQLException: ERROR:  Attribute "test this, too,again
" not found


    at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)

.

.

.


If I replace the double quote with single and run this update in the
SQL Commander window of DbVisualizer, it works fine.


Table is:


create table site_sifre(

site_sifreid char(25),

userName char(25),

sifre char(15),

confirmDate timestamp

);



Using:


JDK 1.4.1

Mac OSX, 10.2.4

PostgreSQL 7.3

PostgreSQL Native Driver

PostgreSQL 7.3.1 JDBC2 jdbc driver build 107


DbVisualizer gives in depth info regarding Database, and what setting
are. Too lengthy to include here, but here are a few:


Attribute

-----------------------------------    --------

.

.

storesUpperCaseQuotedIdentifiers    false

storesLowerCaseQuotedIdentifiers    false

storesMixedCaseQuotedIdentifiers    false

getIdentifierQuoteString        "

getSearchStringEscape            \

.

.</color></fixed>
Gentle people,

When I run the following code, I get the resulting output which
PostgreSQL balks at. Is there a switch or something to yield single
quote? Kindly advise.

Code snippet: (from TableExample)

             String query =
                 "update site_sifre"+
      //hard coded the tablename as String tableName =
                 " set "+columnName+" = "+dbRepresentation(column,
value)+    // metaData.getTableName(column+1); returns "null"
                 " where ";
             // We don't have a model of the schema so we don't know the
             // primary keys or which columns to lock on. To demonstrate
             // that editing is possible, we'll just lock on everything.
             for(int col = 0; col<getColumnCount(); col++) {
                 String colName = getColumnName(col);
                 if (colName.equals("")) {
                     continue;
                 }
                 if (col != 0) {
                     query = query + " and ";
                 }
                 query = query + colName +" = "+
                     dbRepresentation(col, getValueAt(row, col));
                             }
             System.out.println(query);
             //System.out.println("Not sending update to database");
             statement.executeQuery(query);
         }
         catch (SQLException e) {
             e.printStackTrace();
             System.err.println("Update failed");
         }
         Vector dataRow = (Vector)rows.elementAt(row);
         dataRow.setElementAt(value, column);

     }

=====  OUTPUT ===
update site_sifre set username = "test this, too,again           "
where site_sifreid = "realOnePlayer            " and username = "test
this, too           " and sifre = "ssssssss       " and confirmdate =
"2003-03-14 19:18:50.319598"
java.sql.SQLException: ERROR:  Attribute "test this, too,again
  " not found

    at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)
.
.
.

If I replace the double quote with single and run this update in the
SQL Commander window of DbVisualizer, it works fine.

Table is:

create table site_sifre(
site_sifreid char(25),
userName char(25),
sifre char(15),
confirmDate timestamp
);


Using:

JDK 1.4.1
Mac OSX, 10.2.4
PostgreSQL 7.3
PostgreSQL Native Driver
PostgreSQL 7.3.1 JDBC2 jdbc driver build 107

DbVisualizer gives in depth info regarding Database, and what setting
are. Too lengthy to include here, but here are a few:

Attribute
-----------------------------------    --------
.
.
storesUpperCaseQuotedIdentifiers    false
storesLowerCaseQuotedIdentifiers    false
storesMixedCaseQuotedIdentifiers    false
getIdentifierQuoteString        "
getSearchStringEscape            \
.
.

pgsql-jdbc by date:

Previous
From: Jeff Kolesky
Date:
Subject: Multiple open ResultSets not allowed?
Next
From: Vernon Wu
Date:
Subject: Re: Single quote instead of double?