Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid charecter for single quotes for sql string in java

Tags:

java

mysql

I am getting the "Invalid character constant" due to single quot in java sql string, i need double quote which i have put in single quote

new StringBuffer("SELECT REPLACE(u.nombre,',',' ') as Organizacion,  ")
    .append(" CONCAT(' " ',REPLACE(s.direccion,',',' '),'"') as Street, '""' as Street2,")
like image 699
Ashish Chaurasia Avatar asked Oct 22 '22 08:10

Ashish Chaurasia


2 Answers

You have to escape quotes in java string literals :

.append(" CONCAT('\"',REPLACE(s.direccion,',',' '),'\"') as Street, '\"\"' as Street2,")
like image 76
Denys Séguret Avatar answered Nov 01 '22 19:11

Denys Séguret


You want to add " in the string but the problem is you did not escape it causing to break the whole string.

You need to escape it using \, ex.

" CONCAT('\"',REPLACE(s.direccion,',',' '),'\"') as Street, '\"\"' as Street2,"
like image 43
John Woo Avatar answered Nov 01 '22 19:11

John Woo