• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HSQLDB whats the proper way to escape stuff?

 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting the following error:

java.sql.SQLException: Unexpected token: S in statement [s]

I'm 90% sure its a problem with an apostrophe (I'm trying to put some fairly large blocks of text into the database). I have function to escape single quotes:


but it doesn't seem to make any difference =/

-Tad
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you tell what is input string ?
[ March 19, 2005: Message edited by: Shailesh Chandra ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35269
383
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tad,
If you use a PreparedStatement, the driver takes care of the escape characters. This is recommended because then you don't have to write extra logic.
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always liked writing out the sql "by hand" prepared statements always sort of bugged me. But I'll try it here and see if it helps.


-Tad
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prepared statements always sort of bugged me


This astounds me. How do prepared statements "bug you"? They are the best and correct way to parameterize SQL statements.
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like seeing exactly what sql statement is going into the database. I dunno I like seeing the string that will be executed. Call me odd.

That being said I stopped getting the error when I used the prepared statement, but I don't know why (which bugs me).

Sometimes I build the query string piece by piece (I guess it would still be possible to do this with a PreparedStatement, but the method of doing it that way seems less intuitive to me).

-Tad
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic