Write a JAVA program to accept the details of teacher (Tno,TName,Sal) from the user, store it into the table and update the salary of employee to entered salary amount and eno is entered employee eno.

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

class Slip11
{
    public static void main(String args[])
    {
        Connection con;
        ResultSet rs;
        Statement state;
        try
        {
           

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

System.out.println("Driver Loaded");
           

con=DriverManager.getConnection("jdbc:odbc:myd

sn");
           

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

br=new BufferedReader(new

InputStreamReader(System.in));
           

System.out.println("Enter Teacher Number: ");
            int

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

System.out.println("Enter Name: ");
            String

name=br.readLine();
           

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

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

            String sql="insert

into teacher values(?,?,?)";
            PreparedStatement

p=con.prepareStatement(sql);
            p.setInt(1,no);
            p.setString(2,name);
            p.setInt(3,sal);
            p.executeUpdate();
           

System.out.println("Record Added");

           

System.out.println("Enter Teacher Number for the

record you wish to Update: ");
           

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

System.out.println("Enter new Name: ");
            name=br.readLine();
           

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

sal=Integer.parseInt(br.readLine());
            sql="update teacher

set Name=?, Salary=? where Code=?";
           

p=con.prepareStatement(sql);
            p.setString(1,name);
            p.setInt(2,sal);
            p.setInt(3,no);
            p.executeUpdate();
           

System.out.println("Record Updated");   
           
            p.close();
            con.close();

        }catch(Exception e)
        {
           

System.out.println(e);
        }
    }
}

2 comments:

  1. thanks Friend, my name Arun, am Studieng in TYBCA i was in very tension regarding soln of practical slips, i got finally...from u...thank u so much....

    ReplyDelete
  2. thx dude, would u plz help me out for my syspro tybcs practical programs

    ReplyDelete