Code example for ResultSet

Methods: close, getString, next

0
    private void butSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butSearchActionPerformed
        try { 
            String sql2 = "select * from drugs where drugId='" + txtDrugId.getText() + "'";
            ResultSet rst = stm.executeQuery(sql2);
 
            if (rst.next() == false) {
                JOptionPane.showMessageDialog(this, "No Record Found!", "Open MRM System", javax.swing.JOptionPane.INFORMATION_MESSAGE);
                return; 
            } else { 
                txtDrug.setText(rst.getString("drug"));
                txtUnit.setText(rst.getString("unit"));
                txtRate.setText(rst.getString("rate"));
                txtLastChanged.setText(rst.getString("lastChanged"));
            } 
            rst.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error Occured!", "Open MRM System", javax.swing.JOptionPane.ERROR_MESSAGE);
        } 
    }//GEN-LAST:event_butSearchActionPerformed 
 
    private void txtDrugIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDrugIdActionPerformed