jdbc where like parameter code example

Example: jdbc where like parameter

private List getTopics (Connection conn, String searchCriteria)
throws SQLException
{
  List blogs = new LinkedList();
  String query = "SELECT id, text FROM blogs WHERE UPPER(text) LIKE ?";
  try
  {
    // going to do a search using "upper"
    searchCriteria = searchCriteria.toUpperCase();

    // create the preparedstatement and add the criteria
    PreparedStatement ps = conn.prepareStatement(query);
    ps.setString(1, "%" + searchCriteria + "%");
    
 ...
 
}

Tags:

Java Example