Wednesday, 24 January 2018

Advancedjava-Slip27



Slip27
Q1. Write a JDBC program to delete the details of given employee (ENo EName Salary). Accept employee ID through command line.   



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

class EmployeeDelete{
            public static void main(String args[]){
                        try{
                                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             con=DriverManager.getConnection("jdbc:odbc:lab.dsn");

                                    int eid = Integer.parseInt(args[0]);

                                    PreparedStatement ps = con.prepareStatement("delete from employees where eno=?");

                                    ps.setInt(1,eid);

                                    if(ps.executeUpdate()==1)
                                                System.out.println("Employee "+eid+" deleted successfully.");
                                    else
                                                System.out.println("Employee "+eid+" not found.");

                                    con.close();
                        }
                        catch(Exception e){
                                    System.out.println(e);
                        }
            }
}                                                                      
                                                                                                                                                                                                                                                                                                                                                                                   
Q2.  Write a Multithreading  program in java to create an applet that contains a TextField to show time. The time should be displayed in the hh:mm:ss format. The thread should start when the user clicks the Start button and stop when the user clicks the stop button. Initialize the values to current time.

import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class slip27 extends Frame implements

ActionListener,Runnable
 {
   Button start,stop;
                 TextField tf;
      int x=0,y=0;
     String msg="";

   Thread t1=new Thread(this);
      public slip27()
       {
             setLayout(new FlowLayout());
             start=new Button("start");
             stop=new Button("stop");
            add(start);
            add(stop);

         start.addActionListener(this);
         stop.addActionListener(this);
                  addWindowListener(new

WindowAdapter()
                     {
                        public void

windowClosing(WindowEvent e)
                         {
                           System.exit(0);
                            }
                      });
                     
                     setSize(200,200);
                     setVisible(true);
              }
 
  public void actionPerformed(ActionEvent ae)
     {
             Button btn=(Button)ae.getSource();
              if(btn==start)
              {
                  t1.start();
                 }
        

      if(btn==stop)
              {
                  t1.stop();
                 }
}


public void run()
 {
   try
   {
      while(true)
       {
          repaint();
          Thread.sleep(350);
         }
  }


catch(Exception e)
{
  }
 }

public void paint(Graphics g)
  {
           
            int sec,min,hr;
            GregorianCalendar date = new GregorianCalendar();
            sec = date.get(Calendar.SECOND);
            min = date.get(Calendar.MINUTE);
            hr = date.get(Calendar.HOUR);
            msg = hr+":"+min+":"+sec;
            g.drawString(msg,10,y+=10);
  }

  public static void main(String args[])
    {
     new slip27();
      }
   }