dcsimg
Special Character (') Handling in JDBC
5 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   govind_raj
Posted On:   Wednesday, June 20, 2001 02:10 PM

I did follow your solution, but it didn't work. what I have is :

ResultSet rset = stmt.executeQuery("SELECT c_keyword FROM keywor
d WHERE c_keyword like '%raj/'s%' {escape '/'}");

But when I use as above I get this error :
SQLException : java.sql.SQLException: ORA-00933: SQL command not properly ended

Can somebody help me in fixing this.

I appreciate your help.

Regards
Raj

Re: Special Character (') Handling in JDBC

Posted By:   Bernie_Acs  
Posted On:   Thursday, November 8, 2001 01:54 PM

substitute ' with '||chr(39)||' which will yield '

The SQL Parse will convert the function to the character an be a happy camper.


This will always work, but a bit cumbrsome type read through.

Any special character can be handled in this fashion of using character ( ascii code ) function .

Re: Special Character (') Handling in JDBC

Posted By:   Bozidar_Dangubic  
Posted On:   Thursday, June 21, 2001 10:55 AM

use prepared statement. therefore, you could do something like this:


PreparedStatement ps = conn.prepareStatement("SELECT c_keyword FROM keyword WHERE c_keyword like ?") ;
String likeStr = "%raj's%" ;
ps.setString(1, likeStr) ;



This way you do not need to worry about escaping anything and it is the most appropriate way to handle this.

Re: Special Character (') Handling in JDBC

Posted By:   Pankaj_Makhija  
Posted On:   Thursday, June 21, 2001 06:38 AM

If you want to Handle the special character (') in the SQL query with JDBC then put another (') with the original one. Say in table "ABC", Field "XYZ" you want to insert the following string : "It's Pankaj Makhija's B'day"

then the Insert query will be like :

"INSERT INTO ABC (XYZ) VALUES ('It''s Pankaj Makhija''s B''day')".

Try this and let me know if it works

Thanks. :)

Re: Special Character (') Handling in JDBC

Posted By:   Anonymous  
Posted On:   Wednesday, June 20, 2001 04:22 PM

Luigi is right, there is an FAQ (http://www.jguru.com/faq/view.jsp?EID=8881). Unfortunately it uses your solution and it seems that the two pieces of code are almost the same.


There is something, though, that it could be an issue (unless it's just a typo): there is a space in the FROM clause between 'keywor' and 'd'.
But I don't think this is the issue.

Regards.

Re: Special Character (') Handling in JDBC

Posted By:   Luigi_Viggiano  
Posted On:   Wednesday, June 20, 2001 03:51 PM

If I am not wrong, I've seen question in the FAQs. Just repeating twice the ' should be enough.
About | Sitemap | Contact