I am inserting data into a table in an Oracle sqldeveloper database and I want to check some things like (that the employee number already exists or that it is not entered correctly, that the boss does not exist, that the salary> 0, and that there is no department code) among others but I do not know how to check what the user has entered with what is in the table before entering this data. This is my code to enter the data:
int emp_no, dir, dept_no;
float salario, comision;
String apellido, oficio, fecha;
String insertEmployee = "INSERT INTO EMPLEADOS (?,?,?,?,?,?,?,?)";
PreparedStatement pstmt1 = con.prepareStatement(insertEmployee);
System.out.println("Indica el numero de treballador: ");
emp_no = keyboard.nextInt();
System.out.println("Indica el cognom del treballador: ");
keyboard.nextLine();
apellido = keyboard.nextLine();
System.out.println("Indica l'ofici del treballador: ");
oficio = keyboard.nextLine();
System.out.println("Indica el numero del director del treballador: ");
dir = keyboard.nextInt();
System.out.println("Indica el dia quan es va contractar el treballador: ");
keyboard.nextLine();
fecha = keyboard.nextLine();
sdf.parse(fecha);
System.out.println("Indica el salari del treballador: ");
salario = keyboard.nextFloat();
System.out.println("Indica la comissio del treballador: ");
comision = keyboard.nextFloat();
System.out.println("Indica el numero de departament al que pertany el treballador: ");
dept_no = keyboard.nextInt();
pstmt1.setInt(1, emp_no);
pstmt1.setString(2, apellido);
pstmt1.setString(3, oficio);
pstmt1.setInt(4, dir);
pstmt1.setString(5, fecha);
pstmt1.setFloat(6, salario);
pstmt1.setFloat(7, comision);
pstmt1.setInt(8, dept_no);
pstmt1.executeUpdate();
con.commit();}