I have a JComboBox
, I want to find data from database using a combo box filter the search. But this code does not work.
String txt = cmbItem.getSelectedItem().toString();
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
cn = cfg.getCon();
String qr = "SELECT ProductName FROM product WHERE ProductName LIKE '%" + txt + "%' limit 5";
ps = cn.prepareStatement(qr);
rs = ps.executeQuery();
while (rs.next()) {
String name = rs.getString("ProductName");
}
cmbItem.addItem(rs.getString("ProductName"));
} catch (SQLException e) {
} finally {
cfg.close_connection(cn, ps, rs);
}
Comments
Post a Comment