Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
what is useful(benefit) of slash in this code?! "db.execSQL(" DELETE FROM " + "TABLE_PRODUCTS" + "WHERE " + COLUMN_PRODUCTNAME + "=\"" + ProductName + "\";");"

What I have tried:

what is useful(benefit) of slash in this code?! "db.execSQL(" DELETE FROM " + "TABLE_PRODUCTS" + "WHERE " + COLUMN_PRODUCTNAME + "=\"" + ProductName + "\";");"
Posted
Updated 21-May-17 5:49am

1 solution

The slash is the Java character escape: it means that the following character is special, and should not have it's normal meaning. In this case \" says 'insert a double quote in the string instead of terminating the string'
"A\"B\"C"
Would give you a string containing
A"B"C
There are several "special" codes in Java:
\b   Backspace
\f   Form feed
\n   Newline
\t   Tab
\r   Carriage return
\"   Double quote
\\   Backslash

But please, do yourself a favour and don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900