Find out more about what we do

Header Ads

CS506 assignment no 1 solution spring 2022 || cs506 Web Design and Development assignment 1 solution spring 2022

 CS506  assignment no 1 solution spring 2022 || cs506 Web Design and Development assignment 1 solution spring 202

Problem Statement:

After,After, the Covid19 crisis, government of Pakistan has decided to give the relief in medical sector to their employees, so that people can avail free medical treatment. For this purpose, government want to launch a portal name “Sehat-Card Registration Form” to collect the data of the people who wants to avail free medical treatment. You are required to write a Java program for that portal which will help them to collect the data from the employees

           

D       Detailed Description

etaYou have to create a database in MS Access and add a table in the database. The name of database should be “employee” and the name of table should be “records”. Records table will have six attributes i.e. fname, cnic, gender, pno, city and district. Once the Add button is pressed, the entered data will be visible on the screen in the table format as well as the same data will also be saved in the MS Access file







Solution:

methods for adding Records:
     public void aadRecords() throws ClassNotFoundException, SQLException ,NullPointerException {

     
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            String url = "jdbc:ucanaccess://assets//employee.accdb";
            Connection con = DriverManager.getConnection(url);

            String query = "INSERT INTO records (fname,cnic,gender,pno,city,district) VALUES(?,?,?,?,?,?)";
            PreparedStatement pst = con.prepareStatement(query);

            pst.setString(1, fullNameTxt.getText());
            pst.setString(2, fullNameTxt1.getText());
            pst.setString(3, fullNameTxt2.getText());
            pst.setString(4, fullNameTxt3.getText());
            pst.setString(5, fullNameTxt4.getText());
            pst.setString(6, fullNameTxt5.getText());

            pst.executeUpdate();

            JOptionPane.showMessageDialog(this, "Record Added Successfully");
            showRecords();
    }


Method for Showing Records:

  public void showRecords() {

        DefaultTableModel model;
        model = (DefaultTableModel) Data_table.getModel();
        model.setRowCount(0);

        try {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            String url = "jdbc:ucanaccess://assets//employee.accdb";
            Connection con = DriverManager.getConnection(url);
            String sql = "SELECT * FROM records ";

            PreparedStatement pst = con.prepareStatement(sql);

            ResultSet rs = pst.executeQuery();

            while (rs.next()) {

                Object[] obj = {
                    rs.getString("ID"),
                    rs.getString("fname"),
                    rs.getString("cnic"),
                    rs.getString("gender"),
                    rs.getString("pno"),
                    rs.getString("city"),
                    rs.getString("district")};
                
                model = (DefaultTableModel) Data_table.getModel();
                model.addRow(obj);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

/////////////////////////////////////////////////////////////////////

Part 1


Part 2





NetBeans IDE

Ucanasccess Driver

Post a Comment

0 Comments