Pushp
Pushp

Reputation: 65

How to handle forward slash(/) in java jdbc while querying for a particular value?

Below is my query which is successfully working in command window but in JDBC I am unable to get the result set for this.

select * From Elp_Dealer_Recon_Wrk where CERTIFICATE='FACTURA MTY10745/24';

The same query if I use in cmd window it will return the result set and in jdbc its not returning any result set

Instead of FACTURA MTY10745/24 if I am giving some other value in the table its fetching the records in jdbc.

Can anyone help me on this please

Upvotes: 4

Views: 952

Answers (1)

Youcef LAIDANI
Youcef LAIDANI

Reputation: 59986

Like @OrangeDog mention in comment, to avoid such errors you have to use PreparedStatement, here is an example you can follow :

String str = "FACTURA MTY10745/24";
String query = "Select DATE_COMP From ELP_DEALER_RECON_WRK WHERE CERTIFICATE = ?";
//-----------------------------------------------------------------------------^
try(PreparedStatement pst = con.prepareStatement(query)){
    pst.setString(1, str);// Set the input
    ResultSet result = pst.executeQuery();
    //... get results
}

Upvotes: 3

Related Questions