Assignment

You can send and view your assignment on this page

12 comments:

  1. public class emp
    {
    private String name;
    private String id;
    private String phno;
    public void getdata(String name,String id,String phno)
    {
    this.name=name;
    this.id=id;
    this.phno=phno;
    }
    public void show()
    {
    System.out.println("name :"+name);
    System.out.println("id :"+id);
    System.out.println("phone number :"+phno);
    }
    }

    ReplyDelete
  2. hello sir..
    ive made this prog...n m gettin a prob..tat this prog doesn't write the content into the file....
    employyee naam ki file is generatin bt...contauning garbage value....plz check this out...

    ReplyDelete
  3. gaurav it shows garbage value bcoz u r nt returning da result na...!!

    ReplyDelete
  4. {
    information info=new information(arg[0]);
    try
    {
    BufferReader in=new BufferReader(new FileReader(info));
    String s;
    s=in.readLine();
    while(s!=null)
    {
    System.out.println("Read:"+s);
    s=in.readLine();
    }
    in.close();
    }
    catch(FileNotFoundException e1)
    {
    System.err.println(File not found :"+info);
    }
    catch(IOException e2)
    {
    e2.printStackTrace();
    }
    }

    ReplyDelete
  5. HELLO SIR,

    how cn we apply it sir...?

    ReplyDelete
  6. new program through which you can write an object as well as read an object from an file is uploaded in program folder

    ReplyDelete
  7. gaurav u did mistake emp should be serialized so that its object can be written

    ReplyDelete
  8. //emp.java


    import java.io.*;
    import java.util.*;
    public class emp implements Serializable
    {
    private String name;
    private String id;
    private String phno;
    public emp(){}
    public emp(String name,String id,String phno)
    {
    this.name=name;
    this.id=id;
    this.phno=phno;
    }
    public void getdata(String name,String id,String phno)
    {
    this.name=name;
    this.id=id;
    this.phno=phno;
    }
    public void show()
    {
    System.out.println("name :"+name);
    System.out.println("id :"+id);
    System.out.println("phone number :"+phno);
    }
    }

    ReplyDelete
  9. hello sir,
    mene emp.java as well as employee1.java me kuch changes kiye hai.
    but shayad me employee1.java me set theek se impliment nahin kar paya,wo abhi bhi over write kar raha hai.
    aap ek baar check kar lena....

    ReplyDelete
  10. hello sir..
    m giving u the code.plz chekthis out..m getting many errors..n not able to correct them..

    ReplyDelete
  11. import javax.swing.*;
    import java.awt.*;
    import java.sql.*;
    public class ProductInfo extends JFrame implements ActionListener
    {
    JLabel heading,id,desc,rate,quantity,unit_msr,empty_label,error;
    JTextField idField,descField,rateField,quantityField,unit_msrField;
    JButton insert,update,delete,clear,exit;
    JComboBox idCombo;
    PreparedStatement stat;
    Statement stmt;
    Connection con;
    ResultSet rs;
    JPanel jpl;
    public ProductInfo()
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:MYDataSource","administrator","");
    stmt=con.createStatement();
    rs=stmt.executQuery("SELECT p_id FROM product");
    while (rs.next())
    {
    idCombo.addItem(Integer.toString(rs.getInt(1)));
    }
    con.close();
    }
    catch(Exception e)
    {
    System.out.println("Error : "+e);
    }
    idCombo.addActionListener(this);
    }

    public void actionPerformed(ActionEvent ae)
    {
    if(ae.getActionCommand()=="Exit")
    System.exit(0);
    if(ae.getActionCommand()=="Delete")
    {
    try
    {
    con=DriverManager.getConnection("jdbc:odbc:MyDataSource","administrator","");
    stat=con.prepareStatement("DELETE from product WHERE p_id= ?");
    String selected_id=idCombo.getSelectedItem.toString();
    int id=Integer.parseInt(selected_id);
    stat.setInt(1,id);
    stat.executeUpdate();
    con.close();
    idCombo.removeActionListener(this);
    con=DriverManager.getConnection("jdbc:odbc:MyDataSource","administrator","");
    stmt=con.createStatement();
    rs=stmt.executeQuery("SELECT p_id FROM product");
    idCombo.removeAllIems();
    while(rs.next())
    {
    idCombo.addItem(Integer.toString(rs.getInr(1)));
    }
    con.close();
    idCombo.addActionListener(this);
    idField.setText();
    descField.setText();
    rateField.setText();
    quantityField.setText();
    unit_msrField.setText();
    error.setText("row deleted");
    }
    catch(Exception e)
    {
    System.out.println("Error : "+e);
    error.setText("row cannot be deleted");
    }
    }

    if(ae.ActionCommand=="Insert")
    {
    try
    {
    con=DriverManager.getConnection("jdbc:odbc:MyDataSource","adinistrator","");
    stat=con.prepareStatement("INSERT INTO product VALUES(?,?,?,?,?)");
    String id=idField.getText();
    String description = descFiled.getText();
    String rate = rateField.getText();
    String quantity = quantityField.getText();
    String unit_measure= unit_msrField.getText();
    stat.setInt(1,Integer.parseInt(id));
    stat.setString(2,description);
    stat.setDouble(3,Double.parseDouble(rate));
    stat.setInteger(4,Integer.parseInt(quantity));
    stat.setString(5,unit_measure);
    stat.executeQuery();
    con.close();
    idCombo.removeActionListener(this);
    con.DriverManager.getConnection("jdbc:odbc:MyDataSource","administrator","");
    stmt=con.createStatement();
    rs=stmt.executeQuery("SELECT p_id FROM product");
    idCombo.removeAllItems();
    while(rs.next())
    {
    idCombo.addItem(Integer.toString(rs.getInt(1)));
    }
    con.close();
    idCombo.addActionListener(this);
    error.setText("row inserted");
    }
    catch(Exception e)
    {
    System.out.println("Error :"+e);
    error.setText("row cannot be inserted");
    }
    }
    }
    }

    ReplyDelete
  12. public class product
    {
    public static void main(String a[])
    {
    ProductInfo p=new ProductInfo();
    p.show();
    }
    }

    ReplyDelete