aspose file tools
The moose likes JDBC and the fly likes How to parse hyphen in form post? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "How to parse hyphen in form post?" Watch "How to parse hyphen in form post?" New topic
Author

How to parse hyphen in form post?

Chuan Ren
Ranch Hand

Joined: Aug 04, 2003
Posts: 42
I am doing a form post to get a description input from user.

I am using Oracle database. When the data entered consist of ', (, ) it will break the sql Statement. What can I do to solve this problem?
Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56554
    
  14

Not a JSP question, so I'm moving this along to the JDBC forum.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26499
    
  78

Chuan,
You can either escape the special characters (like single quote) with a backslash or use a prepared statement. I recommend the prepared statement because it takes care of these details for you.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Chuan Ren
Ranch Hand

Joined: Aug 04, 2003
Posts: 42
I am learning this from Mastering JSP chapter 13 which uses the connection manager bean. The sample code from the book is such:

The code seems tidy from a JSP page. however if it's a form post, and the l_username contains hyphen or ' or ), the sql statement breaks. How do I incorporate prepare statement in the above situation?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26499
    
  78

Sun's short course has a good example. Just scroll down to the section on prepared statements.
Since the example was from a book on JSPs, the author was probably trying to explain how to do a query in the most basic way than to provide an extremely robust solution.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to parse hyphen in form post?
 
Similar Threads
MS Access Insert - last row missing
how to test (junit4) this mysql funciton?
Help on simple SQL required!!
Identifier expected, (already searched and read about this, still confused
How to get pair values using getParameterNames?