Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 20 Answers

 


A) Write a JDBC program to delete the details of given employee (ENo EName

Salary). Accept employee ID through command line.

Answer :    

import java.sql.*;

public class EmployeeDelete {
  public static void main(String[] args) {
    if (args.length != 1) {
      System.out.println("Usage: EmployeeDelete <employee_id>");
      return;
    }
    int employeeId = Integer.parseInt(args[0]);

    try {
      // Load the JDBC driver
      Class.forName("com.mysql.jdbc.Driver");
     
      // Connect to the database
      Connection conn = DriverManager.getConnection(
          "jdbc:mysql://localhost/mydatabase", "username", "password");
     
      // Prepare the SQL statement
      PreparedStatement pstmt = conn.prepareStatement(
          "DELETE FROM Emp WHERE ENo = ?");
      pstmt.setInt(1, employeeId);
     
      // Execute the SQL statement
      int rowsDeleted = pstmt.executeUpdate();
      if (rowsDeleted == 0) {
        System.out.println("No employee found with ID " + employeeId);
      } else {
        System.out.println("Employee with ID " + employeeId + " deleted successfully");
      }
     
      // Close the database connection
      pstmt.close();
      conn.close();
    } catch (Exception e) {
      System.out.println("Error: " + e.getMessage());
    }
  }
}

Output :

 

B) Write a java program in multithreading using applet for drawing temple.

Answer :

import java.awt.*;

 

public class Slip20B extends Frame {

 

    int f = 0;

 

    public Slip20B() {

        Signal s = new Signal();

        s.start();

        setSize(500, 500);

        setVisible(true);

    }

 

    public void paint(Graphics g) {

        switch (f) {

 

            case 0:

                g.drawRect(100, 150, 90, 120);

            case 1:

                g.drawRect(130, 230, 20, 40);

            case 2:

                g.drawLine(150, 100, 100, 150);

            case 3:

                g.drawLine(150, 100, 190, 150);

            case 4:

                g.drawLine(150, 50, 150, 100);

            case 5:

                g.drawRect(150, 50, 20, 20);

        }

    }

 

    class Signal extends Thread {

        public void run() {

            while (true) {

                f = (f + 1) % 5;

                repaint();

                try {

                    Thread.sleep(1000);

                } catch (Exception e) {

 

                }

            }

        }

    }

 

    public static void main(String args[]) {

        new Slip20B();

    }

}


Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 20 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 20 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

No comments:

Powered by Blogger.