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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
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: 61761
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

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://aspose.com/file-tools
 
subject: How to parse hyphen in form post?