Write a JAVA program to accept the empno from the user and update the salary of employee and display the updated Record on the screen. Employee having fields empno , ename and salary.

import java.io.*;
import java.sql.*;

class slip7
{
    public static void main(String args[])throws SQLException,IOException,ClassNotFoundException
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        Connection con=DriverManager.getConnection("jdbc:odbc:mdsn");
        Statement stmt=con.createStatement();
        /*System.out.println("Enter Employee name ");
                    String name=br.readLine();
                    System.out.println("Enter Employee number  ");
                        int no=Integer.parseInt(br.readLine());
                        System.out.println("Enter Employee salary ");
                        int sal=Integer.parseInt(br.readLine());
                        String sql="insert into emp values('"+name+"',"+no+","+sal+")";
                        System.out.println("sql  "+sql);
                        int count=stmt.executeUpdate(sql);
                        if(count>0)
                        System.out.println("Added");
                        else
                        System.out.println("Not Added");*/
        System.out.println("*********************Update record*********************");
        System.out.println("Enter empno");
                        int eno=Integer.parseInt(br.readLine());
                        System.out.println("Enter new salary");
                        int esal=Integer.parseInt(br.readLine());
                        //String abv=;
                        //System.out.println(" "+eno+"  "+esal+"  "+abv);
                       
                        PreparedStatement p=null;
                        p=con.prepareStatement("update h12 set  esal=? where empno=?");
                        p.setInt(1,esal);
                        p.setInt(2,eno);
                        int count=p.executeUpdate();
                        if(count>0)
                        System.out.println("Updated");
                        else
                        System.out.println("Not updated");
        }
    }

No comments:

Post a Comment