import java.sql.*;
import java.io.*;
import javax.sql.*;
public class Emsa
{
public static void main(String args[])
{
int ch;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from Empdirc");
while(rs.next())
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.Display all the Records from the Table");
System.out.println("4.Check PRIVILAGE LEAVE and Casual Leaves");
System.out.println("5.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();
System.out.println("11.STATUS");
String s=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.setString(11,s);
public static boolean abcd(String str)
{
int x;
for(int mob= 0 ; mob < str.length() ; mob++)
{
x = (int)str.charAt(mob);
if( x < 10 || x > 0)
return false;
}
return true;
}
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=?, Mob=? , Email=?, Sal=? , fi=? where Eid=?";
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(5,emfi);
ps.setInt(6,emnum);
ps.executeUpdate();
System.out.println("Record Updated");
//p.close();
//con.close();
break;
case 3 : System.out.println("Displaying the Data ");
//Statement stmt=con.createStatement();
ResultSet res=stmt.executeQuery("select * from Empdirc");
while(res.next())
System.out.println("Eid"+res.getInt(1)+"Ename "+res.getString(2)+"Design "+res.getString(3)+"Dob "+res.getString(4)+"Mobile no."+res.getString(5)+"Email "+res.getString(6)+"Salary "+res.getString(7));
break;
case 4 : System.out.println("CALCULATING");
sql="update EmpDirc set Pl=?, Cl=? where Estatus=?";
PreparedStatement pes=con.prepareStatement(sql);
pes.setInt(1,15);
pes.setInt(2,07);
pes.setString(3,"permanent");
pes.executeUpdate();
System.out.println("Record Updated");
case 5:
System.exit(0);
break;
default:
System.out.println("Invalid Choice");
break;
}
}while(ch!=2);
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}