Skip to content
Advertisement

how to make search bar without having to type double quotation?

hello everyone i am trying to make this search bar in java but when i search without typing double quotation i get this error

search error image

but when i type numbers or words with double quotation it works just fine

searching with double quotation image

here is my code

Code image

ididn’t wirte anything in the textfield

Advertisement

Answer

Change this one line But beware of SQL injection

Basically you need to wrap the where clause entry in double quotes your first query generates

Which means you are asking give me all rows which have column value URL equal to column value google

The right query is

Now you are asking give me all rows whose URL is equal to “google” string

In the first case your code fails saying I cant find a column named google

EDIT

Basically you should not directly string interpolate your variables that will lead to security issues

You can refer how to do prepared statement here

Java – escape string to prevent SQL injection

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement