public void createComicFilter(String name, String number, String variant,
String sign, String editorial, String format,
String procedence, String year, String writer,
String sketcher) throws SQLException {
ArrayList<String> strFilter = new ArrayList<>();
String connector = " WHERE ";
StringBuilder sql = new StringBuilder();
sql.append("SELECT * FROM comicsbbdd");
if (name != null) {
sql.append(connector).append("name = ?");
connector = " AND ";
strFilter.add(name);
}
if (number != null) {
sql.append(connector).append("number = ?");
connector = " AND ";
strFilter.add(number);
}
if (variant != null) {
sql.append(connector).append("variant = ?");
connector = " AND ";
strFilter.add(variant);
}
// Así por cada campo
PreparedStatement ps = con.prepareStatement(sql.toString());
for (int i = 0; i < strFilter.size(); ) {
ps.setString(++i, strFilter.get(i - 1));
}
ResultSet rs = ps.executeQuery();
// Aquí ya haces el manejo de tus datos
while(rs.next()){
break;
}
}