ja26
- Write a Java program to delete the details of given employee (ENo EName Salary).
Accept employee ID through command line. (Use PreparedStatement Interface)
[15 M]
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DeleteEmployee {
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: java DeleteEmployee <employeeId>");
return;
}
int employeeId = Integer.parseInt(args[0]);
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
// Establish connection to the database
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "username", "password");
// Create a prepared statement for deleting employee details
String sql = "DELETE FROM employee WHERE ENo = ?";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1, employeeId);
// Execute the delete operation
int rowsAffected = preparedStatement.executeUpdate();
if (rowsAffected > 0) {
System.out.println("Employee details deleted successfully.");
} else {
System.out.println("Employee not found with ID: " + employeeId);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
// Close the resources
try {
if (preparedStatement != null) {
preparedStatement.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
- Write a JSP program to calculate sum of first and last digit of a given number. Display
sum in Red Color with font size 18.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>