Single quote instead of double?

Поиск
Список
Период
Сортировка
Искать

Single quote instead of double?

От:
Oguz Imre <maccube@comcast.net>
Дата:
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)


0C0C,FFFF,3535            String query =

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

                F4F4,7979,9C9C" set
"0C0C,FFFF,3535+columnName+F4F4,7979,9C9C"
= "0C0C,FFFF,3535+dbRepresentation(column,
value)+    //
0C0B,FFFE,3534metaData.getTableName(column0000,0000,FFFE+10C0B,FFFE,3534);
returns "null"0C0C,FFFF,3535

                F4F4,7979,9C9C" where
"0C0C,FFFF,3535;

            A5A5,1C1C,DCDC// We don't
have a model of the schema so we don't know the0C0C,FFFF,3535

            A5A5,1C1C,DCDC// primary
keys or which columns to lock on. To demonstrate0C0C,FFFF,3535

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

           
FFFF,5E5E,CACAfor0C0C,FFFF,3535(FFFF,5E5E,CACAint0C0C,FFFF,3535
col =
0000,0000,FFFF00C0C,FFFF,3535;
col<FFFF,5E5E,CACAif0C0C,FFFF,3535 (colName.equals(F4F4,7979,9C9C""0C0C,FFFF,3535)) {

                   
FFFF,5E5E,CACAcontinue0C0C,FFFF,3535;

                }

               
FFFF,5E5E,CACAif0C0C,FFFF,3535 (col
!=
0000,0000,FFFF00C0C,FFFF,3535) {

                    query = query +
F4F4,7979,9C9C" and
"0C0C,FFFF,3535;

                }

                query = query + colName
+F4F4,7979,9C9C" =
"0C0C,FFFF,3535+

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

                            }

            System.out.println(query);

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

            statement.executeQuery(query);

        }

       
FFFF,5E5E,CACAcatch0C0C,FFFF,3535 (SQLException
e) {

            e.printStackTrace();

           
System.err.println(F4F4,7979,9C9C"Update
failed"0C0C,FFFF,3535);

        }

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

        dataRow.setElementAt(value, column);


    }


00A2,0017,00EA=====  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			\

.

.
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

Re: Single quote instead of double?

От:
Vernon Wu <vernonw@gatewaytech.com>
Дата:
You need to pad a backslash in front of the apostrophe, or double up the apostrophe. Here is an example code:

		int k=0;
		while((k = src.indexOf("'", k)) >= 0) {
			src = src.substring(0, k) + "\\" + src.substring(k);
			k += 2;
		}
		return src;
*

15/03/2003 10:28:10 AM, Oguz Imre  wrote:




Re: Single quote instead of double?

От:
Oguz Imre <maccube@comcast.net>
Дата:
Thanks for your swift response.

You are suggesting that after I create the query string, I edit it to 
substitute single quote with double, then execute the query. I agree 
this is a trivial solution, I wanted to know if there is an elegant 
way, say by some switches or something...

Have a nice day.


On Saturday, March 15, 2003, at 01:35  PM, Vernon Wu wrote:

> You need to pad a backslash in front of the apostrophe, or double up 
> the apostrophe. Here is an example code:
>
> 		int k=0;
> 		while((k = src.indexOf("'", k)) >= 0) {
> 			src = src.substring(0, k) + "\\" + src.substring(k);
> 			k += 2;
> 		}
> 		return src;
> *
>
> 15/03/2003 10:28:10 AM, Oguz Imre  wrote:
>
>
>
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

Past Single quote instead of double? But there's more

От:
Oguz Imre <maccube@comcast.net>
Дата:
Now I get the following error message. I display a table, then edit
one of the cells, so I update the row. Can anyone suggest What I am
doing wrong.

Thanks


=================

before edit

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


after edit

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

No results were returned by the query.

	at
org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:157)

	at
org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1Statement.java:141)

	at JDBCAdapter.setValueAt(JDBCAdapter.java:240)

	at TableSorter.setValueAt(TableSorter.java:278)

	at javax.swing.JTable.setValueAt(JTable.java:1783)

	at javax.swing.JTable.editingStopped(JTable.java:3129)

	at
javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:124)

	at
javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:328)

	at
javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:213)

	at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:3460)

	at
javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCellEditor.java:345)

	at javax.swing.JTextField.fireActionPerformed(JTextField.java:489)

	at javax.swing.JTextField.postActionEvent(JTextField.java:670)

	at
javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:784)

	at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1510)

	at javax.swing.JComponent.processKeyBinding(JComponent.java:2435)

	at javax.swing.JComponent.processKeyBindings(JComponent.java:2470)

	at javax.swing.JComponent.processKeyEvent(JComponent.java:2398)

	at java.awt.Component.processEvent(Component.java:4902)

	at java.awt.Container.processEvent(Container.java:1566)

	at java.awt.Component.dispatchEventImpl(Component.java:3598)

	at java.awt.Container.dispatchEventImpl(Container.java:1623)

	at java.awt.Component.dispatchEvent(Component.java:3439)

	at
java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1688)

	at
java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:593)

	at
java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:765)

	at
java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:698)

	at
java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:559)

	at java.awt.Component.dispatchEventImpl(Component.java:3468)

	at java.awt.Container.dispatchEventImpl(Container.java:1623)

	at java.awt.Window.dispatchEventImpl(Window.java:1585)

	at java.awt.Component.dispatchEvent(Component.java:3439)

	at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)

	at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:230)

	at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:183)

	at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)

	at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

	at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

Update failed



On Saturday, March 15, 2003, at 01:28  PM, Oguz Imre wrote:


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)


0C0B,FFFE,3534            String query =

                F4F3,7978,9C9B"update
site_sifre"0C0B,FFFE,3534+                                        
//hard coded the tablename as String tableName = 

                F4F3,7978,9C9B" set
"0C0B,FFFE,3534+columnName+F4F3,7978,9C9B"
= "0C0B,FFFE,3534+dbRepresentation(column,
value)+    //
0C0A,FFFD,3533metaData.getTableName(column0000,0000,FFFD+10C0A,FFFD,3533);
returns "null"0C0B,FFFE,3534

                F4F3,7978,9C9B" where
"0C0B,FFFE,3534;

            A5A4,1C1B,DCDB// We don't
have a model of the schema so we don't know the0C0B,FFFE,3534

            A5A4,1C1B,DCDB// primary
keys or which columns to lock on. To demonstrate0C0B,FFFE,3534

            A5A4,1C1B,DCDB// that
editing is possible, we'll just lock on everything.0C0B,FFFE,3534

           
FFFE,5E5D,CAC9for0C0B,FFFE,3534(FFFE,5E5D,CAC9int0C0B,FFFE,3534
col =
0000,0000,FFFE00C0B,FFFE,3534;
col<FFFE,5E5D,CAC9if0C0B,FFFE,3534 (colName.equals(F4F3,7978,9C9B""0C0B,FFFE,3534)) {

                   
FFFE,5E5D,CAC9continue0C0B,FFFE,3534;

                }

               
FFFE,5E5D,CAC9if0C0B,FFFE,3534 (col
!=
0000,0000,FFFE00C0B,FFFE,3534) {

                    query = query +
F4F3,7978,9C9B" and
"0C0B,FFFE,3534;

                }

                query = query + colName
+F4F3,7978,9C9B" =
"0C0B,FFFE,3534+

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

                            }

            System.out.println(query);

           
A5A4,1C1B,DCDB//System.out.println("Not
sending update to database");0C0B,FFFE,3534

            statement.executeQuery(query);

        }

       
FFFE,5E5D,CAC9catch0C0B,FFFE,3534 (SQLException
e) {

            e.printStackTrace();

           
System.err.println(F4F3,7978,9C9B"Update
failed"0C0B,FFFE,3534);

        }

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

        dataRow.setElementAt(value, column);


    }


00A1,0016,00E9=====  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			\

.

. 
Now I get the following error message. I display a table, then edit one  
of the cells, so I update the row. Can anyone suggest What I am doing  
wrong.
Thanks

=================
before edit
update site_sifre set username = "test this, too. Please!  " where  
site_sifreid = "realOnePlayer            " and username = "test this,  
too. Please!  " and sifre = "sekizlik       " and confirmdate =  
"2003-03-14 19:18:50.319598"

after edit
update site_sifre set username = 'test this, too. Please!  ' where  
site_sifreid = 'realOnePlayer            ' and username = 'test this,  
too. Please!  ' and sifre = 'ssssssss       ' and confirmdate =  
'2003-03-14 19:18:50.319598'
No results were returned by the query.
	at  
org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1St 
atement.java:157)
	at  
org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(AbstractJdbc1St 
atement.java:141)
	at JDBCAdapter.setValueAt(JDBCAdapter.java:240)
	at TableSorter.setValueAt(TableSorter.java:278)
	at javax.swing.JTable.setValueAt(JTable.java:1783)
	at javax.swing.JTable.editingStopped(JTable.java:3129)
	at  
javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.jav 
a:124)
	at  
javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCell 
Editor.java:328)
	at  
javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:213 
)
	at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:3460)
	at  
javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCell 
Editor.java:345)
	at javax.swing.JTextField.fireActionPerformed(JTextField.java:489)
	at javax.swing.JTextField.postActionEvent(JTextField.java:670)
	at  
javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:784)
	at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1510)
	at javax.swing.JComponent.processKeyBinding(JComponent.java:2435)
	at javax.swing.JComponent.processKeyBindings(JComponent.java:2470)
	at javax.swing.JComponent.processKeyEvent(JComponent.java:2398)
	at java.awt.Component.processEvent(Component.java:4902)
	at java.awt.Container.processEvent(Container.java:1566)
	at java.awt.Component.dispatchEventImpl(Component.java:3598)
	at java.awt.Container.dispatchEventImpl(Container.java:1623)
	at java.awt.Component.dispatchEvent(Component.java:3439)
	at  
java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java: 
1688)
	at  
java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFoc 
usManager.java:593)
	at  
java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboard 
FocusManager.java:765)
	at  
java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboard 
FocusManager.java:698)
	at  
java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusM 
anager.java:559)
	at java.awt.Component.dispatchEventImpl(Component.java:3468)
	at java.awt.Container.dispatchEventImpl(Container.java:1623)
	at java.awt.Window.dispatchEventImpl(Window.java:1585)
	at java.awt.Component.dispatchEvent(Component.java:3439)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
	at  
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThrea 
d.java:230)
	at  
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread. 
java:183)
	at  
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
	at  
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
Update failed


On Saturday, March 15, 2003, at 01:28  PM, Oguz Imre wrote:

> 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                 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			\
> .
> . 

Re: Past Single quote instead of double? But there's more

От:
"Michael Paesold" <mpaesold@gmx.at>
Дата:
Oguz Imre wrote:
> Now I get the following error message. I display a table, then
> edit one of the cells, so I update the row. Can anyone suggest
> What I am doing wrong.
> Thanks

> No results were returned by the query.
> at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(..)

> statement.executeQuery(query);

executeQuery is for SELECT queries or other queries that return a ResultSet.
Use the "int executeUpdate(String sql)" method of the Statement object for
UPDATE queries (that return no ResultSet).

Best Regards,
Michael

Re: Past Single quote instead of double? But there's more

От:
Oguz Imre <maccube@comcast.net>
Дата:
Thanks for your reply, Michael.

It works just fine, now.

Regards,

Oguz

On Saturday, March 15, 2003, at 06:17  PM, Michael Paesold wrote:

> Oguz Imre wrote:
>> Now I get the following error message. I display a table, then
>> edit one of the cells, so I update the row. Can anyone suggest
>> What I am doing wrong.
>> Thanks
>
>> No results were returned by the query.
>> at org.postgresql.jdbc1.AbstractJdbc1Statement.executeQuery(..)
>
>> statement.executeQuery(query);
>
> executeQuery is for SELECT queries or other queries that return a 
> ResultSet.
> Use the "int executeUpdate(String sql)" method of the Statement object 
> for
> UPDATE queries (that return no ResultSet).
>
> Best Regards,
> Michael
>
>
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

FAQ