Skip to main content

Q) Develop a JDBC application that prompts the end-user to enter an employee number and displays the salary details.



A)

//Retrieval.java

import java.util.Scanner;
importjava.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
class Retrieval {

       public static void main(String[] args) {
              Scanner s= new Scanner(System.in);System.out.println("Enter employee number");
              int eno =s.nextInt();
              Connection con=DriverManager.getConnection("jdbc:odbc:mydsn","scott","tiger"");" +
                           Statement st=con.createStatement();
                           ResultSet rs= st.executeQuery("SELECT ESAL FROM EMPLOYEE WHERE EID :"+eno);
                           if(rs.next()){
                                  float sal= rs.getFloat(1);
                                  System.out.println("Employee salary : Rs."+sal);
                           }
                           else
                                  System.out.println("Employee doesn't exest");
                           rs.close();
                           st.close();
                           con.close();
       }
}

Comments