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,empname and salary.


import java.sql.*;

import java.io.*;

import javax.sql.*;


public class slip7

    {

     public static void main(String args[])

    {

     Connection con=null;

     Statement state=null;

     ResultSet rs=null;

   

    try

    {

     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    con=DriverManager.getConnection("jdbc:odbc:my1dsn.dsn");

    state=con.createStatement();

    System.out.println("Statement object created");

    int amt;

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    rs=state.executeQuery("Select * from employee1");

    System.out.println("Record before update");

    System.out.println();

    System.out.println("Empno"+"\t"+"Emp Name"+"\t"+"Salary");

    while(rs.next())

    {

    System.out.println("\n");

    System.out.println("\t"+rs.getInt(1));

    System.out.println("\t"+rs.getString(2));

    System.out.println("\t"+rs.getInt(3));

    }

   

    System.out.println("Enter Employee no. for the record you wish to update:");

     int no=Integer.parseInt(br.readLine());


    System.out.println("Enter new Salary:");

    int sal=Integer.parseInt(br.readLine());


     int rowsUpdated=state.executeUpdate("Update employee1 set employee1.sal="+sal+"  where(((employee1.[no])="+no+"))");

    System.out.println("no of rows updated: "+rowsUpdated);

    rs=state.executeQuery("Select * from employee1");

    System.out.println("records updated:");

    System.out.println();

    System.out.println("Empno"+"\t"+"Emp Name"+"\t"+"Salary");

    while(rs.next())

    {

    System.out.println("\n");

    System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3));

        }

    rs.close();

    state.close();

    con.close();

    }

    catch(Exception e)

    {

    System.out.println(e);

    }}}
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,empname and salary. 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,empname and salary. Reviewed by on April 27, 2015 Rating: 5
Powered by Blogger.