Friday , December 13 2019

JAVA #32 – Java application using SQL server (Part: 03)

Submit Button Code

        String INTPUTQUERY = "Insert into tblUser Values('"+txtName.getText().toString()+"','"+txtEmail.getText().toString()+"','"+txtPass.getText().toString()+"',"+txtAge.getText().toString()+")";
        objDB = new DBContext();
        try {
            objDB.ExeQuery(INTPUTQUERY);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
        }
        ResetInsert();
        JOptionPane.showMessageDialog(this, "Data Inserted");

Show Button Code

        String ShowQuery = "Select * From tblUser";
            objDB = new DBContext();
        try {
            ResultSet rs = objDB.ShowData(ShowQuery);
            TAMessage.setText("");
            TAMessage.append("ID        Name         Email        Password        Age\n");
            while(rs.next())
            {            
            TAMessage.append(rs.getString(1)+" "+ rs.getString(2)+" "+ rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5)+"\n");
            }            
                        
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
        }

 

 

About Faheem

Faheem
An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

JAVA #31 – Exception Handling In Java

Video In Progress…

Leave a Reply

Your email address will not be published.