Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java SQL LIKE Prepared Statement

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB

Hello,

I am attempting to run a wildcard match in a Prepared Statement using a Placeholder, unfortunatley this doesnt seem to work. I think the statement is trying to match the entire string dis. Does anyone have a suggestion of how this should be done, i cannot find any examples on the Internet.

My Code is below.

Thank you in advance for your help.

Mark.


String dis = "'%"+district.trim()+"%'";

try {
// build and execute procedure


PreparedStatement findStmt = con.prepareStatement("SELECT DISTINCT (venuid) FROM venue WHERE street LIKE ?");

findStmt.setString(1,dis);
ResultSet rs = findStmt.executeQuery();

while (rs.next()) {

v.add(rs.getString(1));
}

con.commit();
findStmt.close();

} catch (SQLException e) {
e.printStackTrace();
con.rollback();
System.out.println("ERROR 2702: CLASS DistrictDB:" +e);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top