Ashish Chaurasia
Ashish Chaurasia

Reputation: 1737

invalid charecter for single quotes for sql string in java

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,")

Upvotes: 5

Views: 1022

Answers (2)

John Woo
John Woo

Reputation: 263683

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,"

Upvotes: 1

Denys Séguret
Denys Séguret

Reputation: 382092

You have to escape quotes in java string literals :

.append(" CONCAT('\"',REPLACE(s.direccion,',',' '),'\"') as Street, '\"\"' as Street2,")

Upvotes: 2

Related Questions