Write a java program to accept the details of teacher(Tno,TName) from user and store it into the table and update the salary of the employee to entered salaty amount and eno is entered employee eno.
import java.sql.*; import java.io.*; import javax.sql.*; public class slip11 { 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 details of teacher(Tno,TName) from user and store it into the table and update the salary of the employee to entered salaty amount and eno is entered employee eno.
Reviewed by
on
April 27, 2015
Rating: