import java.sql.*;
import java.io.*;
import javax.sql.*;
class Ems
{
public static void main(String args[])
{
int ch;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@finn:1521:orcl","hr","hr");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from EmpDirc");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5)
+" "+rs.getString(6)+" "+rs.getString(7));
do
{
System.out.println("\n");
System.out.println(" ENTER EMPLOYEE DETAILS:");
System.out.println("1.Insert Record into the Table");
System.out.println("2.Update The Existing Record.");
System.out.println("3.CALCULATE PRIVILAGE LEAVE");
System.out.println("4.Display all the Records from the Table");
System.out.println("5.Exit");
System.out.println("Enter your choice: ");
System.out.println("4.Exit");
System.out.println("Enter your choice: ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println("1.INSERT EMPLOYEE ID.");
int num= Integer.parseInt(br.readLine());
System.out.println("2.INSERT EMPLOYEE NAME");
String ename=br.readLine();
System.out.println("3.INSERT EMPLOYEE DESIGNATION");
String desig=br.readLine();
System.out.println("4.INSERT EMPLOYEE DATEOFBIRTH");
String dob=br.readLine();
System.out.println("5.INSERT EMPLOYEE PHONE NO OR ANY CONTACT");
String mob= br.readLine();
System.out.println("6.INSERT EMPLOYEE EMAIL ID");
String email= br.readLine();
System.out.println("7.INSERT EMPLOYEE SALARY");
String sal=br.readLine();
System.out.println("8.INSERT EMPLOYEE paid LEAVES");
String pl=br.readLine();
System.out.println("9.INSERT EMPLOYEE CASUAL LEAVES");
String cl=br.readLine();
System.out.println("10.INSERT EMPLOYEE FINAL SALARY");
String fi= br.readLine();
String sql="insert into EmpDirc values(?,?,?,?,?,?,?,?,?,?)";
PreparedStatement p=con.prepareStatement(sql);
p.setInt(1,num);
p.setString(2,ename);
p.setString(3,desig);
p.setString(4,dob);
p.setString(5,mob);
p.setString(6,email);
p.setString(7,sal);
p.setString(8,pl);
p.setString(9,cl);
p.setString(10,fi);
p.executeUpdate();
System.out.println("Record Added");
//p.close();
//con.close();
break;
case 2:
System.out.println("UPDATE EMPLOYEE id : ");
int emnum=Integer.parseInt(br.readLine());
System.out.println("UPDATE EMPLOYEE DESIGNATION : ");
String emdesig=br.readLine();
System.out.println("UPDATE EMPLOYEE PHONE: ");
String emphn=br.readLine();
System.out.println("UPDATE EMPLOYEE EMAIL: ");
String emmail=br.readLine();
System.out.println("UPDATE EMPLOYEE SALARY: ");
String emsal=br.readLine();
System.out.println("UPDATE EMPLOYEE PL: ");
String empl=br.readLine();
System.out.println("UPDATE EMPLOYEE CL: ");
String emcl=br.readLine();
System.out.println("UPDATE EMPLOYEE FINAL SALARY: ");
String emfi=br.readLine();
sql="update EmpDirc set Desig=?, Phnum=? , Email=?, Salary=? , Pl=?, Cl=?, TakeHomeSal=? where Empid=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,emdesig);
ps.setString(2,emphn);
ps.setString(3,emmail);
ps.setString(4,emsal);
ps.setString(5,empl);
ps.setString(6,emcl);
ps.setString(7,emfi);
ps.setInt(8,emnum);
ps.executeUpdate();
System.out.println("Record Updated");
//p.close();
//con.close();
break;
case 3:
System.exit(0);
default:
System.out.println("Invalid Choice");
break;
}
}while(ch!=2);
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}