Question: I have a Oracle database table `MyTable` that has a column `XYZ` with datatype `varchar2(40 Byte)`.

Also there is a row in that table having `XYZ` column's value like `'12345678-1234'`

When I use Oracle SQL client and run select statement: `select * from MyTable where XYZ='12345678-1234';`, it returns **one** record. 

But when I execute same select statement using java (given below), it returns **no** rows. 

```
Connection con = DriverManager.getConnection(url,user,pass);//I have proper parameters here
Statement stmt = con.createStatement();  
String query= "select * from MyTable where XYZ='12345678-1234'";
ResultSet rs = stmt.executeQuery(query);
if (rs.next()){
 System.out.println(rs.getString("XYZ")); 
}else {
 System.out.println("No Value")); 
}

```

Here it always prints **No Value**

**EDIT:** when I use values which are without dash in table rows(for example: '12345678') then both of above gives same result- one row. 

Please point out what I am missing here.

Answer: 
You should use `PreparedStatement`

```
PreparedStatement stmt = con.prepareStatement("select * from MyTable where XYZ = ?");
preparedStatement.setString(1, "12345678-1234");
ResultSet rs = preparedStatement.executeQuery();

```
This was not a problem of java code I found. 

**COMMIT was a culprit.**

I was accessing database from Oracle Sql client and Java simultaneously and that was causing above problem.

Then I used **Commit;** after each statement I execute in Oracle Sql client. *Then problem disappeared.* 

If anyone wants to add some technical details to this then they are most welcome!