Search Criteria GUI Application in Java

Create a Java GUI application that obtains the search criteria from the user and retrieves data from the database based on that.

Search Criteria GUI App in Java

Searching Database MySQL Table

Source Code

import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;
    
private void emptyBtnActionPerformed(java.awt.event.ActionEvent evt) {
    DefaultTableModel model = (DefaultTableModel)empTbl.getModel();
    int rows = model.getRowCount();
    if(rows > 0){
        for(int i = 0; i < rows; i++){
            model.removeRow(0);
        }
    }
}

private void searchBtnActionPerformed(java.awt.event.ActionEvent evt) {
    emptyBtn.doClick();
    DefaultTableModel model = (DefaultTableModel)empTbl.getModel();
    try{
        Class.forName("java.sql.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/employee", "root", "secret");
        Statement stmt = con.createStatement();
        String sfld = (String)srchFldCBX.getSelectedItem();
        String op = (String)opCBX.getSelectedItem();
        String crit = criteriaTF.getText();
        String query = "select empno, empname, job, hiredate, sal, deptno from emp where " + sfld + " " + op + " " + crit + ";";
        ResultSet rs = stmt.executeQuery(query);
        while(rs.next()){
            model.addRow(new Object[]{rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getDouble(5), rs.getInt(6)});
        }
        rs.close();
        stmt.close();
        con.close();
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
}

2 thoughts on “Search Criteria GUI Application in Java”

  1. WAP in Java to enter a natural number ,where N>100 and N<1000,the natural number must not contain zeros. Print all the combinations of the digits of the number including the number itself. Each new combination should appear on a new line. The program displays a message "Invalid Number ",if N1000 or contains zeros.
    Sample Input:
    N=465
    Sample Output:
    456
    465
    546
    564
    645
    654

  2. Sir,a program is given which states that:
    WAP in Java to accept a paragraph containing n no of sentences where n>=1&& n<4. The words are to be separated with a single blank space and are in upper case.A sentence may be terminated either with a '.', '?' ,'!' only. Any other character may be ignored. Perform the following operations:
    1) Accept the no.of sentences. If the number of sentences exceeds the limit, an appropriate error message must be displayed.
    2)Find the number of words in the whole paragraph.
    3) Display the words in ascending order of their frequency. Words with same frequency may appear in any order.
    Eg:
    Sample Input:
    Enter number of sentences:1
    Enter sentences:TO BE OR NOT TO BE.
    Sample Output:
    Total number of words:6
    WORD FREQUENCY
    OR 1
    NOT 1
    TO 2
    BE 2

Leave a Reply

%d bloggers like this: