{"@context":"https://schema.org","@graph":[{"@type":"WebSite","@id":"https://www.onlineteachinghub.com/#website","url":"https://www.onlineteachinghub.com/","name":"Online Teaching Hub","potentialAction":{"@type":"SearchAction","target":"https://www.onlineteachinghub.com/?s={search_term_string}","query-input":"required name=search_term_string"}},{"@type":"ImageObject","@id":"https://www.onlineteachinghub.com/java-32part-04-java-application-using-sql-server-on-jdk-1-8-0/#primaryimage","url":"https://i1.wp.com/www.onlineteachinghub.com/wp-content/uploads/2016/01/GUI-04.jpg?fit=480%2C360&ssl=1","width":480,"height":360},{"@type":"WebPage","@id":"https://www.onlineteachinghub.com/java-32part-04-java-application-using-sql-server-on-jdk-1-8-0/#webpage","url":"https://www.onlineteachinghub.com/java-32part-04-java-application-using-sql-server-on-jdk-1-8-0/","inLanguage":"en-US","name":"JAVA #32 \u2013 Java application using SQL server (Part: 04) | Online Teaching Hub","isPartOf":{"@id":"https://www.onlineteachinghub.com/#website"},"primaryImageOfPage":{"@id":"https://www.onlineteachinghub.com/java-32part-04-java-application-using-sql-server-on-jdk-1-8-0/#primaryimage"},"datePublished":"2016-01-22T19:08:05+05:00","dateModified":"2016-01-29T14:35:33+05:00","author":{"@id":"https://www.onlineteachinghub.com/#/schema/person/c30e48974ce4852f25f77ec79ec71369"}},{"@type":["Person"],"@id":"https://www.onlineteachinghub.com/#/schema/person/c30e48974ce4852f25f77ec79ec71369","name":"Faheem","image":{"@type":"ImageObject","@id":"https://www.onlineteachinghub.com/#authorlogo","url":"https://www.onlineteachinghub.com/wp-content/uploads/2019/05/10512010_661950350566720_39594702_o.jpg","caption":"Faheem"},"description":"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.","sameAs":[]}]}
Wednesday , December 11 2019

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

Get Data Button Code:

        String ShowQuery = "Select * From tblUser Where UID='"+txtID.getText().toString()+"'";
            objDB = new DBContext();
        try {
            ResultSet rs = objDB.ShowData(ShowQuery);            
            while(rs.next())
            {            
                txtUName.setText(rs.getString(2));
                txtUEmail.setText(rs.getString(3));
                txtUPass.setText(rs.getString(4));
                txtUAge.setText(rs.getString(5));
            }            
                        
        } 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);
        }

Update Button Code:

  String UpdateQuery = "Update tblUser SET Name='"+txtUName.getText().toString()+"',Email='"+txtUEmail.getText().toString()+"',Password='"+txtUPass.getText().toString()+"',Age='"+txtUAge.getText().toString()+"' Where UID='"+txtID.getText().toString()+"'";
        
        objDB = new DBContext();
        try {
            objDB.ExeQuery(UpdateQuery);
        } 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 Updated");

Delete Button Code:

       String DelQuery = "Delete From tblUser Where UID='"+txtID.getText().toString()+"'";
        objDB = new DBContext();
        try {
            objDB.ExeQuery(DelQuery);
        } 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, "Record Deleted");

Methods For Reset The Form:

   public void ResetInsert()
    {
        txtName.setText("");
        txtEmail.setText("");
        txtPass.setText("");
        txtAge.setText("");                                
    }
    public void ResetUpdate()
    {
        txtUName.setText("");
        txtUEmail.setText("");        
        txtUPass.setText("");
        txtUAge.setText("");
    }

 

 

 

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…