Please tell me what is the problem with this code

Hai,
Iam new to Swings. can any one tell what is the problem with this code. I cant see those controls on the frame. please give me the suggestions.
I got the frame ,but the controls are not.
this is the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ex2 extends JFrame
JButton b1;
JLabel l1,l2;
JPanel p1,p2;
JTextField tf1;
JPasswordField tf2;
public ex2()
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Another example");
setSize(500,500);
setVisible(true);
b1=new JButton(" ok ");
p1=new JPanel();
p1.setLayout(new GridLayout(2,2));
p2=new JPanel();
p2.setLayout(new BorderLayout());
l1=new JLabel("Name :");
l2=new JLabel("Password:");
tf1=new JTextField(15);
tf2=new JPasswordField(15);
Container con=getContentPane();
con.add(p1);
con.add(p2);
public static void createAndShowGUI()
ex2.setDefaultLookAndFeelDecorated(true);
public static void main(String ar[])
createAndShowGUI();
new ex2();
}

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ex2 extends JFrame
    JButton b1;
    JLabel l1,l2;
    JPanel p1,p2;
    JTextField tf1;
    JPasswordField tf2;
    public ex2()
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setTitle("Another example");
        b1=new JButton(" ok ");
        p1=new JPanel();
        p1.add(b1);
        p2=new JPanel();
        p2.setLayout(new GridLayout(2,2));
        l1=new JLabel("Name :");
        l2=new JLabel("Password:");
        tf1=new JTextField(15);
        tf2=new JPasswordField(15);
        p2.add(l1);
        p2.add(tf1);
        p2.add(l2);
        p2.add(tf2);
        Container con=getContentPane();
        con.add(p1, BorderLayout.NORTH);
        con.add(p2, BorderLayout.CENTER);
        pack();
        setVisible(true);
    public static void createAndShowGUI()
        ex2.setDefaultLookAndFeelDecorated(true);
    public static void main(String ar[])
        createAndShowGUI();
        new ex2();
}

Similar Messages

  • Vector, what is the problem with this code?

    Vector, what is the problem with this code?
    63  private java.util.Vector data=new Vector();
    64  Vector aaaaa=new Vector();
    65   data.addElement(aaaaa);
    74  aaaaa.addElement(new String("Mary"));on compiling this code, the error is
    TableDemo.java:65: <identifier> expected
                    data.addElement(aaaaa);
                                   ^
    TableDemo.java:74: <identifier> expected
                    aaaaa.addElement(new String("Mary"));
                                    ^
    TableDemo.java:65: package data does not exist
                    data.addElement(aaaaa);
                        ^
    TableDemo.java:74: package aaaaa does not exist
                    aaaaa.addElement(new String("Mary"));Friends i really got fed up with this code for more than half an hour.could anybody spot the problem?

    I can see many:
    1. i assume your code snip is inside a method. a local variable can not be declare private.
    2. if you didn't import java.util.* on top then you need to prefix package on All occurance of Vector.
    3. String in java are constant and has literal syntax. "Mary" is sufficient in most of the time, unless you purposly want to call new String("Mary") on purpose. Read java.lang.String javadoc.
    Here is a sample that would compile...:
    public class QuickMain {
         public static void main(String[] args) {
              java.util.Vector data=new java.util.Vector();
              java.util.Vector aaaaa=new java.util.Vector();
              data.addElement(aaaaa);
              aaaaa.addElement(new String("Mary"));
    }

  • Please tell me what's the problem with my procedure ..

    Hi all,
    Below is my procedure i created into a form.( i can't create procedure into table or vieew because there is already negative value )
    PROCEDURE REVERSE_money IS
    nCnt number(10);
    WS_VALID_USER_ID Varchar2(3);
    USER__VIEW_BUF USER_VIEW%ROWTYPE;
    PAYMENT_VIEW_BUF PAYMENT_VIEW%ROWTYPE;
    Cursor USER_VIEW_QRY is
    select * from USER_VIEW
    where USER_ENTERED_CASHIER = USER_VIEW_BUF.USER_ENTERED_CASHIER;
    Cursor PAYMENT_VIEW_QRY is
    select * from PAYMENT_VIEW
    where TOTAL = :PAYMENT_VIEW_SINGLE.TOTAL;
    BEGIN
    if nvl(:PAYMENT_VIEW_SINGLE.TOTAL,' ') = (:pAYMENT_VIEW_SINGLE.TOTAL*-1) then
    SELECT COUNT(*) INTO nCnt
    FROM cashier_auth
    WHERE cashier = UPPER(NVL(USER_VIEW_BUF.CASHIER,' '));
    IF (nCnt > 0) THEN
    WS_VALID_USER_ID := 'YES';
    ELSE
         WS_VALID_USER_ID := 'NO';
    END IF;
    end if;
    IF nvl(WS_VALID_USER_ID,' ') = 'NO' THEN
    MESSAGE(USER || ' is not authorized to enter nagative value to this cash transaction.');
    SET_APPLICATION_PROPERTY(CURSOR_STYLE,'DEFAULT');
    RAISE FORM_TRIGGER_FAILURE;
    END IF;
    END;
    there is no error in this procedure when i compile it , but this procedure is not validating as i wanted, what i meant is is still let any user enter ('-') value.
    someone plese help me.

    Hi,
    pl/sql baby wrote:
    Hi all,
    Below is my procedure i created into a form.( i can't create procedure into table or vieew because there is already negative value ) Sorry, I don't understand this part.
    In fact, I don't understand the whole problem.
    Please explain what the procedure is supposed to do, and what's wrong with it.
    For example
    "The procedure is supposed to show a message and raise an error if ...
    That should happen when the USER is ... and PAYMENT_VIEW_SINGLE.TOTAL < 0, but it is not."
    Post SQL statements to create and populate the tables and views used (such as cashier_auth table). Include enough rows to re-create the problem.
    What are you trying to do in this line?
    if nvl(:PAYMENT_VIEW_SINGLE.TOTAL,' ') = (:pAYMENT_VIEW_SINGLE.TOTAL*-1) thenWhat is the data type of (:PAYMENT_VIEW_SINGLE.TOTAL? If it's a NUMBER, then the second argument of NVL should also be a NUMBER.
    Don't post unformatted code. Type &#123;code&#125; before and after the parts of your message containing code, to preserve spacing.

  • Please Tell Me what is the problem with code

    Dear all,
    As you can see from the attached vi(pictures) after the "home.vi"  nothing happens, after the home.vi both DAQ's and motor controller's vi are not working. Could you pls help me to find a solution about the problem.
    Waiting response.
    Thanks,
    Best regards.
    Solved!
    Go to Solution.
    Attachments:
    WhatistheProblem.png ‏123 KB
    Problem2ndCase.png ‏94 KB
    Motor-LoadReadNew.vi ‏52 KB

    Dear dkfire,
    Firstly thanks alot for your solution, now two loops are working paralel with no problem. But i dont understand what you want to mean with the greedy loop. I need to made 2 loops in order to apply "wait.vi" only to the motor vis. Otherwise the DAQ's vis and motor's drivers vis locate at the same loop which means  DAQ also waits while the motor is waiting. I want DAQ to take samples continuously without waiting. If i put wait.vi to the false structure as you said, then this will make DAQ wait too which is unacceptable. So now it takes my PC's all power?
    Kind Regards,
    Waiting forward for your kind reply.

  • What is the problem with this code ? Race condition??

    Guys,
    The idea behind the attached code is quite simple.
    I have a 2D parent array. First, I print a subset of this array into a table control (based on a sensor selection). Now, I want edit the numbers in the table. I need the changes to be reflected in the table and the parent 2D array. (In simple terms, this is like replacing the the edited array subset into the parent 2D array)
    The problem is when I change(edit) any entry in the table, the entry changes back to its original value. The change doesnt seem to be reflecting on the parent 2D array and the table. .
    Can anyone tell me where the problem is?
    Thanks
    Ravi
    Solved!
    Go to Solution.
    Attachments:
    Alarm threshold test.vi ‏14 KB

    I agree with Chris, here's an idea (of whatI think your code does):
    The case structure in your code was unnecessary, all the cases were the same so I removed them.
    The sequence structure was unnecessary.
    Ton
    Message Edited by TonP on 11-20-2008 07:52 PM
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!
    Attachments:
    Alarm threshold test_BD.png ‏19 KB

  • What is the problem with this code?

    dear sirs...
    i have a page that does not contain any binding, it contains the following event:
    public void onCheck(DataActionContext ctx)
    ViewObject V=ctx.getBindingContext.findDataControl("AppModuleDataControl").getApplicationModule.findViewObject("empview1");
    V.setWhereClause("");
    V.executeQuery();
    V.first();
    note that the above code works if the table emp is on the page, however, if the page is not bound to the page (it does not contains the table) the statement in the bold will fire an exception saying that there is no binding. i am sure the V is not set to null.
    another problem appears, if i put the table and execute it within jdeveloper, it works correctly, however, if i run if i deploy the application into application server, the code never runs as if there is some kind of an error.
    i hope that you can anser me about the following;
    1- if the code above correct?
    2- how can i view the log for the application?
    3- System.out.println("test"); in jdeveloper works okay, in the application server, does it cause some kind of an error?
    thanks for any help & best regards

    If you don't close the ResultSet, different things happen based on which database you're running. You can keep read locks that you don't need. It wastes resources, and as different databases react differently to it, you might have weird bugs down the road that result from your practices of not properly closing ResultSets, PreparedStatements, and Connections. Put this in a loop like you've got here, and the effects may or may not get amplified.
    I write a close() for a ResultSet just as soon as I open it, just to make sure I don't forget. In a situation like this one, I would write something like so:
    for(int i = 0;i<someValue;i++)
    try
    //some code
    rs = pstmt.executeQuery();
    //some code that uses rs
    catch(Exception e)
    finally
      if (rs != null)
        rs.close();
      if (pstmt != null)
        pstmt.close();
    }

  • "When_list_changed" what is the problem with this code???????

    DECLARE
         v_group_grade RECORDGROUP;
         v_pop_group NUMBER;
    BEGIN
         v_group_grade := find_group('group_grade');
         IF NOT id_null(v_group_grade) THEN
                   delete_group(v_group_grade);
         END IF;
         IF :CONTROL_LISTS.STAGE = 1 THEN
              v_group_grade := create_group_from_query('group_grade', 'SELECT grade_name FROM grade WHERE grade_name LIKE ''KG%''');
              v_pop_group := populate_group(v_group_grade);
              populate_list('CONTROL_LISTS.GRADE', v_group_grade);
         ELSIF :CONTROL_LISTS.STAGE = 2 THEN
              v_group_grade := create_group_from_query('group_grade', 'SELECT grade_name FROM grade WHERE grade_name LIKE ''Prim%''');
              v_pop_group := populate_group(v_group_grade);
              populate_list('CONTROL_LISTS.GRADE', v_group_grade);
         ELSIF:CONTROL_LISTS.STAGE = 3 THEN
              v_group_grade := create_group_from_query('group_grade', 'SELECT grade_name FROM grade WHERE grade_name LIKE ''Prep%''');
              v_pop_group := populate_group(v_group_grade);
              populate_list('CONTROL_LISTS.GRADE', v_group_grade);
         ELSE
              NULL;
         END IF;
    END;
    when I change the selection of the STAGE list in the runtime this error apear:
    FRM-41334 invalid record group for list population.

    Thanks Faheem,
    I got it it was in the select statement.
    When I create poplist to fetch data from the database I should select at least two charachter columns.

  • What's the problem in this code

    import java.lang.reflect.*;
    import java.awt.*;
    class ABC
         public Integer i;
         ABC()
         public void setInt(Integer t)
              i = t;
    public class SampleName {
    public static void main(String[] args)
    ABC g1 = new ABC();
    g1.setInt(new Integer(10));
    printFieldNames(g1);
    static void printFieldNames(Object o) {
    Class c = o.getClass();
    Field[] publicFields = c.getDeclaredFields();
    for (int i = 0; i < publicFields.length; i++)
    try {
    Object ref = publicFields.get(c);
    System.out.println(" ref.toString() : " + ref.toString());
         }catch(Exception e)
                   e.printStackTrace();
    What is the problem with this code,at run time Iam getting this exception
    java.lang.IllegalArgumentException: object is not an instance of declaring class
    How can we get the value of field of an object

    Now it got this exception
    java.lang.IllegalAccessException
    at java.lang.reflect.Field.get(Native Method)That's strange - I didn't! ;-)
    Are you running exactly the same code as the code you posted (except for the one line I said to change)?

  • I was playing candy crush and I had too much problem with my bill your charge too much I want to know what is the problem with this game cost

    HELLO
    I was playing candy crush and I had too much problem with my bill your charge too much I want to know what is the problem with this game cost

    Take it up with iTunes Support - we are not Apple here, we are just users like you:
    http://www.apple.com/support/itunes/ww/
    Cheers,
    GB

  • What is the problem with this Stored Procedure

    Hi ,
    What is the problem with this Stored Procedure ?Why is it giving errors ??
    CREATE or replace  PROCEDURE getEmpName
    *(EMP_FIRST OUT VARCHAR2(255))*
    BEGIN
    SELECT ename INTO EMP_FIRST
    FROM Emp
    WHERE EMPNO = 7369;
    END ;
    */*

    You don't specify precision in procedure arguments.
    (EMP_FIRST OUT VARCHAR2(255))should be
    (EMP_FIRST OUT VARCHAR2)Since you asked what's wrong with it, I could add that it needs formatting and the inconsistent use of upper and lower case is not helping readability.

  • Can anybody tell me the problem with this code when compiled in jdk1.4

    Can anybody help me find out the error in this code.
    Try to drag a file from your desktop and drop it on the first textpane on my GUI. Then try to drag another file. This time the dragdrop event handler throws a null pointer exception. This happened when I compiled the code with jdk1.4. With jdk1.3 it is working fine. Actually, I need jdk1.4 to get the systemicons for the files I drop on my desktop.
    /* Client.java*/
    import java.util.Vector;
    import java.util.Enumeration;
    import java.util.Arrays;
    import java.awt.*;
    import java.awt.event.*;
    import java.rmi.*;
    import java.rmi.server.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.filechooser.*;
    import java.io.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    import java.util.Iterator;
    import javax.swing.plaf.*;
    import javax.swing.plaf.basic.*;
    import java.util.Hashtable;
    import javax.swing.text.*;
    import javax.swing.event.*;
    public class Client extends JFrame{
    static String newline = System.getProperty("line.separator");
    static Client client;
         //ServerInterface server;
         //ClientProperties clp;
         Vector v1=new Vector();
         ByteArrayOutputStream out;
         Runtime r1;
         //file objects,together with array of bytes
         Hashtable files=new Hashtable(); //files sent
         Hashtable rfiles=new Hashtable(); //files received
         //file objects,together with button handlers
         Hashtable hfiles=new Hashtable(); //files sent,files received
         JButton button1=new JButton();
         JButton button2=new JButton();
         JButton button3=new JButton();
         JLabel label1=new JLabel();
         JLabel label2=new JLabel();
         JLabel label3=new JLabel();
         JLabel label4=new JLabel();
         JLabel label5=new JLabel();
         JLabel label6=new JLabel();
         JLabel label7=new JLabel();
         JLabel label8=new JLabel();
         JOptionPane dialog=new JOptionPane();
         JFileChooser chooser = new JFileChooser();
         JPanel panel1;
         JPanel panel2;
         DropTarget dtarget;
         DragSource dsource;
         JTextPane textArea1=new JTextPane();
         TextArea textArea2=new TextArea();
         JTextPane textpanel=new JTextPane();
         Style defstyle,style;
         StyledDocument doc,doc1;
         JPopupMenu popup;
         JTree tree;
         JScrollPane jsppane;
         JScrollPane jsp,jsp2;
         DefaultMutableTreeNode top;
         Container cp;
         private String toalias;
         private String togroup;
    private String fromalias;
         private String fromgroup;     
         private boolean CONNECT;
         public Client()
         cp=getContentPane();
         cp.setLayout(null);
              setForeground(java.awt.Color.red);
              setFont(new Font("Dialog", Font.PLAIN, 14));
              setVisible(false);
              label1.setText(" CHAT APPLICATION");
              cp.add(label1);
              label1.setFont(new Font("Dialog", Font.BOLD, 16));
              label1.setBounds(72,20,319,30);
              label2.setText("List of Users Connected.");
              cp.add(label2);
              label2.setForeground(java.awt.Color.blue);
              label2.setFont(new Font("Dialog", Font.BOLD, 12));
              label2.setBounds(24,60,192,26);
              label8.setBounds(280,60,100,26);
              cp.add(label8);
              cp.add(textArea2);
              textArea2.setBounds(204,120,268,90);
              jsppane=new JScrollPane(textArea1);
              doc1=textArea1.getStyledDocument();
              jsppane.setBounds(12,264,456,109);
              cp.add(jsppane);
              label3.setText("TO::");
              cp.add(label3);
              label3.setFont(new Font("Dialog", Font.BOLD, 12));
              label3.setBounds(12,228,36,20);
              cp.add(label4);
              label4.setBackground(java.awt.Color.lightGray);
              label4.setBounds(60,228,172,19);
              label5.setText("SERVER RESPONSE");
              cp.add(label5);
              label5.setFont(new Font("Dialog", Font.BOLD, 12));
              label5.setBounds(204,96,204,21);
              label7.setText("MESSAGE FOR YOU.");
              cp.add(label7);
              label7.setFont(new Font("Dialog", Font.BOLD, 14));
         label7.setBounds(12,371,288,25);
         jsp2=new JScrollPane(textpanel);
         setTextPaneStyle();
    jsp2.setBounds(12,401,456,109);
    cp.add(jsp2);
    button1.setLabel("Send");
              button1.setEnabled(false);
              cp.add(button1);
              button1.setBackground(java.awt.Color.lightGray);
              button1.setForeground(java.awt.Color.black);
              button1.setFont(new Font("Dialog", Font.BOLD|Font.ITALIC, 10));
              button1.setBounds(60,520,78,36);
              button2.setLabel("Attach");
              //button2.setEnabled(false);
              cp.add(button2);
              button2.setBackground(java.awt.Color.lightGray);
              button2.setForeground(java.awt.Color.black);
              button2.setFont(new Font("Dialog", Font.BOLD|Font.ITALIC, 10));
              button2.setBounds(180,520,72,36);
              button3.setLabel("Connect");
              cp.add(button3);
              button3.setBackground(java.awt.Color.lightGray);
              button3.setForeground(java.awt.Color.black);
              button3.setFont(new Font("Dialog", Font.BOLD|Font.ITALIC, 10));
              button3.setBounds(288,520,72,33);
              setSize(500,620);
         show();
         addWindowListener(new WindowEventHandler());
         button1.addActionListener(new ButtonHandler());     
         button2.addActionListener(new ButtonHandler());     
         button3.addActionListener(new ButtonHandler());
         textArea1.addContainerListener(new ComponentHandler());     
         dtarget=new DropTarget(textArea1,new DragDropHandler());
         textArea2.setEnabled(false);
         textpanel.setEnabled(false);
         r1=Runtime.getRuntime();
         r1.addShutdownHook(new onshutdown());
         addMenu();
         cp.repaint();
         //adds attachments to the textArea1     
         synchronized private void addAttach(java.util.List fileList)
         Iterator iterator=fileList.iterator();
         JButton bw;
         while(iterator.hasNext())
              File file=(File)iterator.next();
              Icon icon=chooser.getIcon(file);
              bw=new JButton(icon);
              bw.setBackground(java.awt.Color.gray);
              bw.setToolTipText(file.getAbsolutePath());
              bw.addMouseListener(new AttachmentHandler());
              Dimension d1=new Dimension(icon.getIconWidth(),icon.getIconHeight());
              bw.setMaximumSize(d1);
              hfiles.put(bw,file);          
              textArea1.insertComponent(bw);
              textArea1.setCaretPosition(doc1.getLength());
              bw.setSize(icon.getIconWidth(),icon.getIconHeight());
              //only one file at a time
              break;
         cp.repaint();
    public void setAudioStream(ByteArrayOutputStream out)
    this.out=out;               
    private void addMenu()
         JMenuBar mbar=new JMenuBar();
         mbar.setVisible(true);
         mbar.setBounds(0,0,500,20);
         mbar.setBackground(java.awt.Color.gray);
         //first menu
         JMenu m1=new JMenu("Connection");
         m1.setBounds(0,0,80,20);
         m1.setBackground(java.awt.Color.gray);
         JMenuItem mitem1=new JMenuItem("Connect");
         JMenuItem mitem2=new JMenuItem("Disconnect");
         m1.add(mitem1);
         m1.add(mitem2);
         mitem1.addActionListener(new ButtonHandler());
         mitem2.addActionListener(new ButtonHandler());
         mbar.add(m1);
         //second menu
         JMenu m2=new JMenu("Send...");
         m2.setBounds(90,0,80,20);
         m2.setBackground(java.awt.Color.gray);
         JMenuItem mitem3=new JMenuItem("Send");
         JMenuItem mitem4=new JMenuItem("Send with Audio...");
         mitem3.addActionListener(new ButtonHandler());
         mitem4.addActionListener(new ButtonHandler());
         m2.add(mitem3);
         m2.add(mitem4);
         mbar.add(m2);
         cp.add(mbar);
    private void setTextPaneStyle()
    StyleContext stylecontext =StyleContext.getDefaultStyleContext();
    defstyle=stylecontext.getStyle(StyleContext.DEFAULT_STYLE);
    doc= textpanel.getStyledDocument();
    //style 1
    style= textpanel.addStyle("bold",defstyle);
    StyleConstants.setBackground(style,Color.white);
    StyleConstants.setForeground(style,Color.blue);
    StyleConstants.setItalic(style, false);
    StyleConstants.setBold(style, true);
    StyleConstants.setFontSize(style,16);
    //style 2
    style= textpanel.addStyle("normal",defstyle);
    StyleConstants.setBackground(style,Color.white);
    StyleConstants.setForeground(style,Color.black);
    StyleConstants.setItalic(style, false);
    StyleConstants.setBold(style, false);
    StyleConstants.setFontSize(style,14);      
    //style3
    style= textpanel.addStyle("attach",defstyle);
    StyleConstants.setBackground(style,Color.white);
    StyleConstants.setForeground(style,Color.red);
    StyleConstants.setItalic(style, true);
    StyleConstants.setBold(style, false);
    StyleConstants.setFontSize(style,12);      
    //remote method called by server
    public void addClient(String alias,String group,JTree tree)
         //if old client remove old tree
         if(!alias.equals(""))
         cp.remove(this.jsp);
         //add new tree
         this.tree=tree;
         setTreeModel();
         getSound(2);
         if(!alias.equals(""))
         textArea2.append("\nNew Client:" + alias + "has joined");
         else
         textArea2.append("\nYou have been connected to the Server.");
         jsp=new JScrollPane(this.tree);
    jsp.setBounds(12,96,168,120);
         jsp.setBackground(java.awt.Color.lightGray);
    cp.add(jsp);
    this.tree.addMouseListener(new MouseHandler());
    //remote method called by server
    public void sendMessage(String str,Hashtable rfiles,String alias,String group) throws RemoteException
              receiveMessage(str,rfiles,alias,group);
    //remote method called by server
    public void removeClient(JTree tree,String alias,String group) throws RemoteException
    cp.remove(this.jsp);
    this.tree=tree;
    setTreeModel();
    getSound(3);
    jsp=new JScrollPane(this.tree);
    jsp.setBounds(12,96,168,120);
         jsp.setBackground(java.awt.Color.lightGray);
    cp.add(jsp);
    this.tree.addMouseListener(new MouseHandler());
    textArea2.append("\nClient:" + alias + "has disconnected");                          
    private void receiveMessage(String str,Hashtable rfiles,String alias,String group)
              boolean flag=true;
              UIManager.put("JFrame.activeTitleBackground", new Color(64,128,255));
    UIManager.put("JFrame.activeTitleForeground", Color.white);
    UIManager.put("JFrame.inactiveTitleBackground", new Color(128,128,128));
    UIManager.put("JFrame.inactiveTitleForeground", Color.black);
    SwingUtilities.updateComponentTreeUI(this);
              try{
              if(alias.equals(""))
         doc.insertString(doc.getLength(),"CHATMASTER>>",textpanel.getStyle("bold"));
              doc.insertString(doc.getLength(),str+ newline,textpanel.getStyle("normal"));
              else
              doc.insertString(doc.getLength(),alias + "@" + group + ">>",textpanel.getStyle("bold"));
              doc.insertString(doc.getLength(),str,textpanel.getStyle("normal"));
              //add files to textpanel
              if(rfiles!=null && rfiles.size()>0)
              doc.insertString(doc.getLength(),newline+"Attachments>>",textpanel.getStyle("attach"));
              showattach(rfiles);
              addtoList(rfiles);     
    doc.insertString(doc.getLength(),newline,textpanel.getStyle("normal"));
    catch(Exception e)
              e.printStackTrace();
              dialog.showMessageDialog(client,e.toString(),"Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
         cp.repaint();               
    protected boolean ContactServer(String alias,String servername,String group)
         try{
              //UnicastRemoteObject.exportObject(this);
              //server=(ServerInterface)Naming.lookup("//gpt02d05:5500/" + servername);
         //     server.notifyMe(this,alias,group);
              //change the settings of buttons
              button1.setEnabled(true);
              button2.setEnabled(true);
              button3.setLabel("Disconnect");
              label8.setVisible(true);
              label8.setText(" Welcome::" + alias);
              //putting values of alias and group for sending messages
              fromalias=alias;
              fromgroup=group;
              CONNECT=true;
              return true;
         catch(UnsupportedOperationException e)
         dialog.showMessageDialog(client,"Client with the Same Alias in " + group + " already exists","Error:ChatApplication",JOptionPane.ERROR_MESSAGE);                                   
         try{
              //     UnicastRemoteObject.unexportObject(client,true);
              catch(Exception ev){System.out.println(ev.toString());}     
         catch(Exception e)
              dialog.showMessageDialog(client,"Unable to connect to Server","Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
              try{
              //     UnicastRemoteObject.unexportObject(client,true);
              catch(Exception ev){System.out.println(ev.toString());}     
         return false;      
    public static void main(String args[]) throws RemoteException{
         client=new Client();          
    }//main ends
    public void getSound(int count)
         Toolkit t1=getToolkit();
              for(int i=0;i<count;i++)
              t1.beep();
              try{
                   Thread.sleep(500);
              catch(Exception e){}
    public void setTreeModel()
    ImageIcon i1=new ImageIcon("Lock.gif","No Users");
    ImageIcon i2=new ImageIcon("Connec.gif","Users in Group");
    ImageIcon i3=new ImageIcon("authorbn.gif","An User");
    DefaultTreeCellRenderer dr1= new DefaultTreeCellRenderer();
    dr1.setClosedIcon(i1);
    dr1.setOpenIcon(i2);
    dr1.setLeafIcon(i3);
    dr1.setTextSelectionColor(java.awt.Color.red);
    tree.setCellRenderer(dr1);
    //add received files to the list
    private void addtoList(Hashtable rfiles)
    Enumeration filelist=rfiles.keys();          
    while(filelist.hasMoreElements())          
    File file=(File)filelist.nextElement();
    this.rfiles.put(file,rfiles.get(file));               
    //show the attachments received               
    private void showattach(Hashtable rfiles)
    Enumeration filelist=rfiles.keys();
    dsource=DragSource.getDefaultDragSource();
    JButton b1=null;
    while(filelist.hasMoreElements())
         File file=(File)filelist.nextElement();
         Icon icon=chooser.getIcon(file);
         b1=new JButton(icon);
         b1.setBackground(java.awt.Color.gray);
    b1.setToolTipText(file.getName());
    b1.addMouseListener(new AttachmentHandler());
    Dimension d1=new Dimension(icon.getIconWidth(),icon.getIconHeight());
    b1.setMaximumSize(d1);
    hfiles.put(b1,file);
    textpanel.setCaretPosition(doc.getLength());
    textpanel.insertComponent(b1);
    b1.setSize(icon.getIconWidth(),icon.getIconHeight());
    dsource.createDefaultDragGestureRecognizer(b1, DnDConstants.ACTION_COPY_OR_MOVE,new DragGestureHandler());           
    cp.repaint();
    private void savefile(File file,Object parent)
    //ExtensionFileFilter filter = new ExtensionFileFilter(false);
    //filter.addExtension("txt",true);
    //chooser.setFileFilter(filter);
    int returnVal = chooser.showSaveDialog(client);
    if(returnVal ==JFileChooser.APPROVE_OPTION)
         try{
         FileOutputStream fstream=new FileOutputStream(chooser.getSelectedFile());
         //decide whether the file received or sent is to be saved
         if(((Container)parent).equals(textArea1))
         fstream.write((byte[])files.get(file));
         else
         fstream.write((byte[])rfiles.get(file));
         fstream.close();
         System.out.println(file.getName());          
         catch(Exception e)
         {System.out.println(e.toString()); }
    private void openfile(File file,Object parent)
         File tempfile=null;
         try{
         String fname=file.getName();     
         tempfile=File.createTempFile("temp",fname.substring(fname.lastIndexOf(".")));     
         FileOutputStream fstream=new FileOutputStream(tempfile);
         System.out.println(tempfile.getAbsolutePath());
         //decide whether the file received or sent is to be saved
         if(((Container)parent).equals(textArea1))
         fstream.write((byte[])files.get(file));
         else
         fstream.write((byte[])rfiles.get(file));          
         fstream.close();
    catch(Exception e){System.out.println(e.toString());}
    try{
         Process p1=r1.exec("cmd /c start " + tempfile.getAbsolutePath());
         p1.waitFor();
    catch(Exception e){System.out.println(e.toString());}     
    //inner classes
    class ComponentHandler implements ContainerListener{
    public void componentRemoved(ContainerEvent ev)     
              Container cont=(Container)ev.getChild();
              if(cont.getComponentCount()>0)
              JButton but=(JButton)cont.getComponent(0);
              files.remove((File)hfiles.get(but));
              hfiles.remove(but);
    public void componentAdded(ContainerEvent ev){}
    class AttachmentHandler extends MouseAdapter{
         public void mouseClicked(MouseEvent ev){
         if(ev.getModifiers()==4)
         Component comp=(Component)ev.getSource();
         File file=(File)hfiles.get(comp);
         popup=new JPopupMenu();
         JMenuItem popopen=new JMenuItem("Open");
         JMenuItem popsave=new JMenuItem("Save As..");
         popup.add(popopen);
         System.out.println(comp.getParent().getParent().getClass().toString());
         popopen.addActionListener(new ButtonHandler(file,comp.getParent().getParent()));
         popup.add(popsave);
         popsave.addActionListener(new ButtonHandler(file,comp.getParent().getParent()));
         popup.show(comp,12,12);
    class DragGestureHandler extends Vector implements DragGestureListener,DragSourceListener,Transferable{
    final static int FILE = 0;
    final static int STRING = 1;
    final static int PLAIN = 2;
    DataFlavor flavors[] = {DataFlavor.javaFileListFlavor,DataFlavor.stringFlavor,DataFlavor.plainTextFlavor};
    public void dragDropEnd(DragSourceDropEvent ev){}
    public void dragEnter(DragSourceDragEvent ev){}
    public void dragExit(DragSourceEvent ev){}
    public void dragOver(DragSourceDragEvent ev){}
    public void dropActionChanged(DragSourceDragEvent ev){}
    public void dragGestureRecognized(DragGestureEvent ev)     
              System.out.println("recognized");
              File file=(File)hfiles.get(ev.getComponent());
    addElement(file);
    ev.startDrag(DragSource.DefaultCopyDrop,this,this);
    /* Returns the array of flavors in which it can provide the data. */
    public synchronized DataFlavor[] getTransferDataFlavors() {
         return flavors;
    /* Returns whether the requested flavor is supported by this object. */
    public boolean isDataFlavorSupported(DataFlavor flavor) {
    boolean b = false;
    b |=flavor.equals(flavors[FILE]);
    b |= flavor.equals(flavors[STRING]);
    b |= flavor.equals(flavors[PLAIN]);
         return (b);
    public synchronized Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException,IOException
    if(flavor.equals(flavors[FILE])){return this;}
    else if (flavor.equals(flavors[PLAIN])) {
         return new StringReader(((File)elementAt(0)).getAbsolutePath());
         } else if (flavor.equals(flavors[STRING])) {
         return((File)elementAt(0)).getAbsolutePath();
         } else {
         throw new UnsupportedFlavorException(flavor);
    //inner class for draging in the files on java frame     
    class DragDropHandler implements DropTargetListener{
    public void dragEnter(DropTargetDragEvent ev){     
    public void dragExit(DropTargetEvent ev){
    public void dragOver(DropTargetDragEvent ev){
    public void drop(DropTargetDropEvent ev){
         Transferable tf1=ev.getTransferable();
         DataFlavor fl[]=ev.getCurrentDataFlavors();
         if(ev.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
         ev.acceptDrop (DnDConstants.ACTION_COPY_OR_MOVE);
         try{
         java.util.List fileList = (java.util.List)tf1.getTransferData(DataFlavor.javaFileListFlavor);
    Iterator iterator = fileList.iterator();
    while (iterator.hasNext())
    File file = (File)iterator.next();
    if(file.isFile())
    Icon icon=chooser.getIcon(file);
    FileInputStream fstream=new FileInputStream(file);
    int filedata=(new Double(file.length())).intValue();
    byte bytes[]=new byte[filedata];
    fstream.read(bytes);
    files.put(file,bytes);
    ev.getDropTargetContext().dropComplete(true);
    addAttach(fileList);
    catch(Exception e)
    {System.out.println(e.toString() + "here");}
    public void dropActionChanged(DropTargetDragEvent ev){
    class MouseHandler extends MouseAdapter{
    public void mouseClicked(MouseEvent me)
    TreePath tp=tree.getPathForLocation(me.getX(),me.getY());
    if(tp!=null)
         if(tp.getPathCount()==3)
              toalias=tp.getPathComponent(2).toString();
              togroup=tp.getPathComponent(1).toString();
              System.out.println(toalias);
              if (!(toalias.equals(fromalias) && togroup.equals(fromgroup)))
              System.out.println("hh " + toalias);
              label4.setText(tp.getPathComponent(2).toString() + "_@" + tp.getPathComponent(1).toString());           
    class ButtonHandler implements ActionListener{
         private File file;
         private Object parent;
         //constructors
         public ButtonHandler()
         public ButtonHandler(File file,Object parent)
              this.file=file;
              this.parent=parent;
         //other functions      
         public void actionPerformed(ActionEvent ev){
              String s=ev.getActionCommand();
         System.out.println(s);
              if(s.equals("Send with Audio..."))
              //Audio audio=new Audio(client,false,"CAPTURE");          
              if(s.equals("Disconnect"))
              try{
              // server.disconnect(client);
              client.getSound(3);
              cp.remove(jsp);
              label6.setVisible(false);
              //UnicastRemoteObject.unexportObject(client,true);
              button3.setLabel("Connect");
              textArea2.append("\nYou have been disconnected to Server");
              client.repaint();     
              catch(Exception e)
              System.out.println(e.toString());
              if(s.equals("Connect"))
         //     clp=new ClientProperties(client,false);
         if(s.equals("Save As.."))
         savefile(file,parent);     
         if(s.equals("Open"))
         openfile(file,parent);
              if(s.equals("Attach"))
              //ExtensionFileFilter filter = new ExtensionFileFilter(false);
              //filter.addExtension(".txt",true);
              //filter.setDescription("Text Files(.txt)");
              // chooser.setFileFilter(filter);
              chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
              //chooser.setMultiSelectionEnabled(true);
              int returnVal = chooser.showOpenDialog(client);
              if(returnVal ==JFileChooser.APPROVE_OPTION)
              //File fp[]=chooser.getSelectedFiles();
              File fp[]=new File[1];
              fp[0]=chooser.getSelectedFile();
              int i=0;
              while(i<fp.length)
              try{
              File file=fp;
              Icon icon=chooser.getIcon(file);
    FileInputStream fstream=new FileInputStream(file);
    int filedata=(new Double(file.length())).intValue();
    byte bytes[]=new byte[filedata];
    fstream.read(bytes);
    files.put(file,bytes);
    catch(Exception e){dialog.showMessageDialog(client,e.toString(),"Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
    return; }
    i++;
              java.util.List fileList=Arrays.asList(fp);
              addAttach(fileList);
              if(s.equals("Send"))
              try{
                   if(toalias==null)
                   dialog.showMessageDialog(client,"Select the Recepient First!!","Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
                   return;
                   if(toalias!=null && togroup!=null && (!toalias.equals(fromalias)))
                   // server.sendMessage(textArea1.getText(),files,toalias,togroup,fromalias,fromgroup);
                   textArea1.setText("");
              catch(Exception e)
         e.printStackTrace();
    }//if ends
    class WindowEventHandler extends WindowAdapter{
         public void windowClosing(WindowEvent ev){
              try{
              //server.disconnect(client);
              client.getSound(3);
         //     UnicastRemoteObject.unexportObject(client,true);
              catch(Exception e){System.out.println(e.toString());}
              dispose();
    private class onshutdown extends Thread{
    public void run(){
         try{
              //server.disconnect(client);
              //UnicastRemoteObject.unexportObject(client,true);
              catch(Exception e){}      
    }//run ends          

    Here is the working code :
    There was an error line 724
    File file=fp; -> File file=fp[0];
    Several method were deprecated and try to replace the deprecated static field : DataFlavor.plainTextFlavor which was deprecated since 1.4.
    /* Client.java*/
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.rmi.*;
    import java.rmi.server.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.filechooser.*;
    import java.io.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.basic.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    public class Client extends JFrame{
    static String newline = System.getProperty("line.separator");
    static Client client;
    //ServerInterface server;
    //ClientProperties clp;
    Vector v1=new Vector();
    ByteArrayOutputStream out;
    Runtime r1;
    //file objects,together with array of bytes
    Hashtable files=new Hashtable(); //files sent
    Hashtable rfiles=new Hashtable(); //files received
    //file objects,together with button handlers
    Hashtable hfiles=new Hashtable(); //files sent,files received
    JButton button1=new JButton();
    JButton button2=new JButton();
    JButton button3=new JButton();
    JLabel label1=new JLabel();
    JLabel label2=new JLabel();
    JLabel label3=new JLabel();
    JLabel label4=new JLabel();
    JLabel label5=new JLabel();
    JLabel label6=new JLabel();
    JLabel label7=new JLabel();
    JLabel label8=new JLabel();
    JOptionPane dialog=new JOptionPane();
    JFileChooser chooser = new JFileChooser();
    JPanel panel1;
    JPanel panel2;
    DropTarget dtarget;
    DragSource dsource;
    JTextPane textArea1=new JTextPane();
    TextArea textArea2=new TextArea();
    JTextPane textpanel=new JTextPane();
    Style defstyle,style;
    StyledDocument doc,doc1;
    JPopupMenu popup;
    JTree tree;
    JScrollPane jsppane;
    JScrollPane jsp,jsp2;
    DefaultMutableTreeNode top;
    Container cp;
    private String toalias;
    private String togroup;
    private String fromalias;
    private String fromgroup;
    private boolean CONNECT;
    public Client()
    cp=getContentPane();
    cp.setLayout(null);
    setForeground(java.awt.Color.red);
    setFont(new Font("Dialog", Font.PLAIN, 14));
    setVisible(false);
    label1.setText(" CHAT APPLICATION");
    cp.add(label1);
    label1.setFont(new Font("Dialog", Font.BOLD, 16));
    label1.setBounds(72,20,319,30);
    label2.setText("List of Users Connected.");
    cp.add(label2);
    label2.setForeground(java.awt.Color.blue);
    label2.setFont(new Font("Dialog", Font.BOLD, 12));
    label2.setBounds(24,60,192,26);
    label8.setBounds(280,60,100,26);
    cp.add(label8);
    cp.add(textArea2);
    textArea2.setBounds(204,120,268,90);
    jsppane=new JScrollPane(textArea1);
    doc1=textArea1.getStyledDocument();
    jsppane.setBounds(12,264,456,109);
    cp.add(jsppane);
    label3.setText("TO::");
    cp.add(label3);
    label3.setFont(new Font("Dialog", Font.BOLD, 12));
    label3.setBounds(12,228,36,20);
    cp.add(label4);
    label4.setBackground(java.awt.Color.lightGray);
    label4.setBounds(60,228,172,19);
    label5.setText("SERVER RESPONSE");
    cp.add(label5);
    label5.setFont(new Font("Dialog", Font.BOLD, 12));
    label5.setBounds(204,96,204,21);
    label7.setText("MESSAGE FOR YOU.");
    cp.add(label7);
    label7.setFont(new Font("Dialog", Font.BOLD, 14));
    label7.setBounds(12,371,288,25);
    jsp2=new JScrollPane(textpanel);
    setTextPaneStyle();
    jsp2.setBounds(12,401,456,109);
    cp.add(jsp2);
    button1.setText("Send");
    button1.setEnabled(false);
    cp.add(button1);
    button1.setBackground(java.awt.Color.lightGray);
    button1.setForeground(java.awt.Color.black);
    button1.setFont(new Font("Dialog", Font.BOLD|Font.ITALIC, 10));
    button1.setBounds(60,520,78,36);
    button2.setText("Attach");
    //button2.setEnabled(false);
    cp.add(button2);
    button2.setBackground(java.awt.Color.lightGray);
    button2.setForeground(java.awt.Color.black);
    button2.setFont(new Font("Dialog", Font.BOLD|Font.ITALIC, 10));
    button2.setBounds(180,520,72,36);
    button3.setText("Connect");
    cp.add(button3);
    button3.setBackground(java.awt.Color.lightGray);
    button3.setForeground(java.awt.Color.black);
    button3.setFont(new Font("Dialog", Font.BOLD|Font.ITALIC, 10));
    button3.setBounds(288,520,72,33);
    setSize(500,620);
    show();
    addWindowListener(new WindowEventHandler());
    button1.addActionListener(new ButtonHandler());
    button2.addActionListener(new ButtonHandler());
    button3.addActionListener(new ButtonHandler());
    textArea1.addContainerListener(new ComponentHandler());
    dtarget=new DropTarget(textArea1,new DragDropHandler());
    textArea2.setEnabled(false);
    textpanel.setEnabled(false);
    r1=Runtime.getRuntime();
    r1.addShutdownHook(new onshutdown());
    addMenu();
    cp.repaint();
    //adds attachments to the textArea1
    synchronized private void addAttach(java.util.List fileList)
    Iterator iterator=fileList.iterator();
    JButton bw;
    while(iterator.hasNext())
    File file=(File)iterator.next();
    Icon icon=chooser.getIcon(file);
    bw=new JButton(icon);
    bw.setBackground(java.awt.Color.gray);
    bw.setToolTipText(file.getAbsolutePath());
    bw.addMouseListener(new AttachmentHandler());
    Dimension d1=new Dimension(icon.getIconWidth(),icon.getIconHeight());
    bw.setMaximumSize(d1);
    hfiles.put(bw,file);
    textArea1.insertComponent(bw);
    textArea1.setCaretPosition(doc1.getLength());
    bw.setSize(icon.getIconWidth(),icon.getIconHeight());
    //only one file at a time
    break;
    cp.repaint();
    public void setAudioStream(ByteArrayOutputStream out)
    this.out=out;
    private void addMenu()
    JMenuBar mbar=new JMenuBar();
    mbar.setVisible(true);
    mbar.setBounds(0,0,500,20);
    mbar.setBackground(java.awt.Color.gray);
    //first menu
    JMenu m1=new JMenu("Connection");
    m1.setBounds(0,0,80,20);
    m1.setBackground(java.awt.Color.gray);
    JMenuItem mitem1=new JMenuItem("Connect");
    JMenuItem mitem2=new JMenuItem("Disconnect");
    m1.add(mitem1);
    m1.add(mitem2);
    mitem1.addActionListener(new ButtonHandler());
    mitem2.addActionListener(new ButtonHandler());
    mbar.add(m1);
    //second menu
    JMenu m2=new JMenu("Send...");
    m2.setBounds(90,0,80,20);
    m2.setBackground(java.awt.Color.gray);
    JMenuItem mitem3=new JMenuItem("Send");
    JMenuItem mitem4=new JMenuItem("Send with Audio...");
    mitem3.addActionListener(new ButtonHandler());
    mitem4.addActionListener(new ButtonHandler());
    m2.add(mitem3);
    m2.add(mitem4);
    mbar.add(m2);
    cp.add(mbar);
    private void setTextPaneStyle()
    StyleContext stylecontext =StyleContext.getDefaultStyleContext();
    defstyle=stylecontext.getStyle(StyleContext.DEFAULT_STYLE);
    doc= textpanel.getStyledDocument();
    //style 1
    style= textpanel.addStyle("bold",defstyle);
    StyleConstants.setBackground(style,Color.white);
    StyleConstants.setForeground(style,Color.blue);
    StyleConstants.setItalic(style, false);
    StyleConstants.setBold(style, true);
    StyleConstants.setFontSize(style,16);
    //style 2
    style= textpanel.addStyle("normal",defstyle);
    StyleConstants.setBackground(style,Color.white);
    StyleConstants.setForeground(style,Color.black);
    StyleConstants.setItalic(style, false);
    StyleConstants.setBold(style, false);
    StyleConstants.setFontSize(style,14);
    //style3
    style= textpanel.addStyle("attach",defstyle);
    StyleConstants.setBackground(style,Color.white);
    StyleConstants.setForeground(style,Color.red);
    StyleConstants.setItalic(style, true);
    StyleConstants.setBold(style, false);
    StyleConstants.setFontSize(style,12);
    //remote method called by server
    public void addClient(String alias,String group,JTree tree)
    //if old client remove old tree
    if(!alias.equals(""))
    cp.remove(this.jsp);
    //add new tree
    this.tree=tree;
    setTreeModel();
    getSound(2);
    if(!alias.equals(""))
    textArea2.append("\nNew Client:" + alias + "has joined");
    else
    textArea2.append("\nYou have been connected to the Server.");
    jsp=new JScrollPane(this.tree);
    jsp.setBounds(12,96,168,120);
    jsp.setBackground(java.awt.Color.lightGray);
    cp.add(jsp);
    this.tree.addMouseListener(new MouseHandler());
    //remote method called by server
    public void sendMessage(String str,Hashtable rfiles,String alias,String group) throws RemoteException
    receiveMessage(str,rfiles,alias,group);
    //remote method called by server
    public void removeClient(JTree tree,String alias,String group) throws RemoteException
    cp.remove(this.jsp);
    this.tree=tree;
    setTreeModel();
    getSound(3);
    jsp=new JScrollPane(this.tree);
    jsp.setBounds(12,96,168,120);
    jsp.setBackground(java.awt.Color.lightGray);
    cp.add(jsp);
    this.tree.addMouseListener(new MouseHandler());
    textArea2.append("\nClient:" + alias + "has disconnected");
    private void receiveMessage(String str,Hashtable rfiles,String alias,String group)
    boolean flag=true;
    UIManager.put("JFrame.activeTitleBackground", new Color(64,128,255));
    UIManager.put("JFrame.activeTitleForeground", Color.white);
    UIManager.put("JFrame.inactiveTitleBackground", new Color(128,128,128));
    UIManager.put("JFrame.inactiveTitleForeground", Color.black);
    SwingUtilities.updateComponentTreeUI(this);
    try{
    if(alias.equals(""))
    doc.insertString(doc.getLength(),"CHATMASTER>>",textpanel.getStyle("bold"));
    doc.insertString(doc.getLength(),str+ newline,textpanel.getStyle("normal"));
    else
    doc.insertString(doc.getLength(),alias + "@" + group + ">>",textpanel.getStyle("bold"));
    doc.insertString(doc.getLength(),str,textpanel.getStyle("normal"));
    //add files to textpanel
    if(rfiles!=null && rfiles.size()>0)
    doc.insertString(doc.getLength(),newline+"Attachments>>",textpanel.getStyle("attach"));
    showattach(rfiles);
    addtoList(rfiles);
    doc.insertString(doc.getLength(),newline,textpanel.getStyle("normal"));
    catch(Exception e)
    e.printStackTrace();
    dialog.showMessageDialog(client,e.toString(),"Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
    cp.repaint();
    protected boolean ContactServer(String alias,String servername,String group)
    try{
    //UnicastRemoteObject.exportObject(this);
    //server=(ServerInterface)Naming.lookup("//gpt02d05:5500/" + servername);
    // server.notifyMe(this,alias,group);
    //change the settings of buttons
    button1.setEnabled(true);
    button2.setEnabled(true);
    button3.setText("Disconnect");
    label8.setVisible(true);
    label8.setText(" Welcome::" + alias);
    //putting values of alias and group for sending messages
    fromalias=alias;
    fromgroup=group;
    CONNECT=true;
    return true;
    catch(UnsupportedOperationException e)
    dialog.showMessageDialog(client,"Client with the Same Alias in " + group + " already exists","Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
    try{
    // UnicastRemoteObject.unexportObject(client,true);
    catch(Exception ev){System.out.println(ev.toString());}
    catch(Exception e)
    dialog.showMessageDialog(client,"Unable to connect to Server","Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
    try{
    // UnicastRemoteObject.unexportObject(client,true);
    catch(Exception ev){System.out.println(ev.toString());}
    return false;
    public static void main(String args[]) throws RemoteException{
    client=new Client();
    }//main ends
    public void getSound(int count)
    Toolkit t1=getToolkit();
    for(int i=0;i<count;i++)
    t1.beep();
    try{
    Thread.sleep(500);
    catch(Exception e){}
    public void setTreeModel()
    ImageIcon i1=new ImageIcon("Lock.gif","No Users");
    ImageIcon i2=new ImageIcon("Connec.gif","Users in Group");
    ImageIcon i3=new ImageIcon("authorbn.gif","An User");
    DefaultTreeCellRenderer dr1= new DefaultTreeCellRenderer();
    dr1.setClosedIcon(i1);
    dr1.setOpenIcon(i2);
    dr1.setLeafIcon(i3);
    dr1.setTextSelectionColor(java.awt.Color.red);
    tree.setCellRenderer(dr1);
    //add received files to the list
    private void addtoList(Hashtable rfiles)
    Enumeration filelist=rfiles.keys();
    while(filelist.hasMoreElements())
    File file=(File)filelist.nextElement();
    this.rfiles.put(file,rfiles.get(file));
    //show the attachments received
    private void showattach(Hashtable rfiles)
    Enumeration filelist=rfiles.keys();
    dsource=DragSource.getDefaultDragSource();
    JButton b1=null;
    while(filelist.hasMoreElements())
    File file=(File)filelist.nextElement();
    Icon icon=chooser.getIcon(file);
    b1=new JButton(icon);
    b1.setBackground(java.awt.Color.gray);
    b1.setToolTipText(file.getName());
    b1.addMouseListener(new AttachmentHandler());
    Dimension d1=new Dimension(icon.getIconWidth(),icon.getIconHeight());
    b1.setMaximumSize(d1);
    hfiles.put(b1,file);
    textpanel.setCaretPosition(doc.getLength());
    textpanel.insertComponent(b1);
    b1.setSize(icon.getIconWidth(),icon.getIconHeight());
    dsource.createDefaultDragGestureRecognizer(b1, DnDConstants.ACTION_COPY_OR_MOVE,new DragGestureHandler());
    cp.repaint();
    private void savefile(File file,Object parent)
    //ExtensionFileFilter filter = new ExtensionFileFilter(false);
    //filter.addExtension("txt",true);
    //chooser.setFileFilter(filter);
    int returnVal = chooser.showSaveDialog(client);
    if(returnVal ==JFileChooser.APPROVE_OPTION)
    try{
    FileOutputStream fstream=new FileOutputStream(chooser.getSelectedFile());
    //decide whether the file received or sent is to be saved
    if(((Container)parent).equals(textArea1))
    fstream.write((byte[])files.get(file));
    else
    fstream.write((byte[])rfiles.get(file));
    fstream.close();
    System.out.println(file.getName());
    catch(Exception e)
    {System.out.println(e.toString()); }
    private void openfile(File file,Object parent)
    File tempfile=null;
    try{
    String fname=file.getName();
    tempfile=File.createTempFile("temp",fname.substring(fname.lastIndexOf(".")));
    FileOutputStream fstream=new FileOutputStream(tempfile);
    System.out.println(tempfile.getAbsolutePath());
    //decide whether the file received or sent is to be saved
    if(((Container)parent).equals(textArea1))
    fstream.write((byte[])files.get(file));
    else
    fstream.write((byte[])rfiles.get(file));
    fstream.close();
    catch(Exception e){System.out.println(e.toString());}
    try{
    Process p1=r1.exec("cmd /c start " + tempfile.getAbsolutePath());
    p1.waitFor();
    catch(Exception e){System.out.println(e.toString());}
    //inner classes
    class ComponentHandler implements ContainerListener{
    public void componentRemoved(ContainerEvent ev)
    Container cont=(Container)ev.getChild();
    if(cont.getComponentCount()>0)
    JButton but=(JButton)cont.getComponent(0);
    files.remove((File)hfiles.get(but));
    hfiles.remove(but);
    public void componentAdded(ContainerEvent ev){}
    class AttachmentHandler extends MouseAdapter{
    public void mouseClicked(MouseEvent ev){
    if(ev.getModifiers()==4)
    Component comp=(Component)ev.getSource();
    File file=(File)hfiles.get(comp);
    popup=new JPopupMenu();
    JMenuItem popopen=new JMenuItem("Open");
    JMenuItem popsave=new JMenuItem("Save As..");
    popup.add(popopen);
    System.out.println(comp.getParent().getParent().getClass().toString());
    popopen.addActionListener(new ButtonHandler(file,comp.getParent().getParent()));
    popup.add(popsave);
    popsave.addActionListener(new ButtonHandler(file,comp.getParent().getParent()));
    popup.show(comp,12,12);
    class DragGestureHandler extends Vector implements DragGestureListener,DragSourceListener,Transferable{
    final static int FILE = 0;
    final static int STRING = 1;
    final static int PLAIN = 2;
    DataFlavor flavors[] = {DataFlavor.javaFileListFlavor,DataFlavor.stringFlavor,DataFlavor.plainTextFlavor};
    public void dragDropEnd(DragSourceDropEvent ev){}
    public void dragEnter(DragSourceDragEvent ev){}
    public void dragExit(DragSourceEvent ev){}
    public void dragOver(DragSourceDragEvent ev){}
    public void dropActionChanged(DragSourceDragEvent ev){}
    public void dragGestureRecognized(DragGestureEvent ev)
    System.out.println("recognized");
    File file=(File)hfiles.get(ev.getComponent());
    addElement(file);
    ev.startDrag(DragSource.DefaultCopyDrop,this,this);
    /* Returns the array of flavors in which it can provide the data. */
    public synchronized DataFlavor[] getTransferDataFlavors() {
    return flavors;
    /* Returns whether the requested flavor is supported by this object. */
    public boolean isDataFlavorSupported(DataFlavor flavor) {
    boolean b = false;
    b |=flavor.equals(flavors[FILE]);
    b |= flavor.equals(flavors[STRING]);
    b |= flavor.equals(flavors[PLAIN]);
    return (b);
    public synchronized Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException,IOException
    if(flavor.equals(flavors[FILE])){return this;}
    else if (flavor.equals(flavors[PLAIN])) {
    return new StringReader(((File)elementAt(0)).getAbsolutePath());
    } else if (flavor.equals(flavors[STRING])) {
    return((File)elementAt(0)).getAbsolutePath();
    } else {
    throw new UnsupportedFlavorException(flavor);
    //inner class for draging in the files on java frame
    class DragDropHandler implements DropTargetListener{
    public void dragEnter(DropTargetDragEvent ev){
    public void dragExit(DropTargetEvent ev){
    public void dragOver(DropTargetDragEvent ev){
    public void drop(DropTargetDropEvent ev){
    Transferable tf1=ev.getTransferable();
    DataFlavor fl[]=ev.getCurrentDataFlavors();
    if(ev.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
    ev.acceptDrop (DnDConstants.ACTION_COPY_OR_MOVE);
    try{
    java.util.List fileList = (java.util.List)tf1.getTransferData(DataFlavor.javaFileListFlavor);
    Iterator iterator = fileList.iterator();
    while (iterator.hasNext())
    File file = (File)iterator.next();
    if(file.isFile())
    Icon icon=chooser.getIcon(file);
    FileInputStream fstream=new FileInputStream(file);
    int filedata=(new Double(file.length())).intValue();
    byte bytes[]=new byte[filedata];
    fstream.read(bytes);
    files.put(file,bytes);
    ev.getDropTargetContext().dropComplete(true);
    addAttach(fileList);
    catch(Exception e)
    {System.out.println(e.toString() + "here");}
    public void dropActionChanged(DropTargetDragEvent ev){
    class MouseHandler extends MouseAdapter{
    public void mouseClicked(MouseEvent me)
    TreePath tp=tree.getPathForLocation(me.getX(),me.getY());
    if(tp!=null)
    if(tp.getPathCount()==3)
    toalias=tp.getPathComponent(2).toString();
    togroup=tp.getPathComponent(1).toString();
    System.out.println(toalias);
    if (!(toalias.equals(fromalias) && togroup.equals(fromgroup)))
    System.out.println("hh " + toalias);
    label4.setText(tp.getPathComponent(2).toString() + "_@" + tp.getPathComponent(1).toString());
    class ButtonHandler implements ActionListener{
    private File file;
    private Object parent;
    //constructors
    public ButtonHandler()
    public ButtonHandler(File file,Object parent)
    this.file=file;
    this.parent=parent;
    //other functions
    public void actionPerformed(ActionEvent ev){
    String s=ev.getActionCommand();
    System.out.println(s);
    if(s.equals("Send with Audio..."))
    //Audio audio=new Audio(client,false,"CAPTURE");
    if(s.equals("Disconnect"))
    try{
    // server.disconnect(client);
    client.getSound(3);
    cp.remove(jsp);
    label6.setVisible(false);
    //UnicastRemoteObject.unexportObject(client,true);
    button3.setText("Connect");
    textArea2.append("\nYou have been disconnected to Server");
    client.repaint();
    catch(Exception e)
    System.out.println(e.toString());
    if(s.equals("Connect"))
    // clp=new ClientProperties(client,false);
    if(s.equals("Save As.."))
    savefile(file,parent);
    if(s.equals("Open"))
    openfile(file,parent);
    if(s.equals("Attach"))
    //ExtensionFileFilter filter = new ExtensionFileFilter(false);
    //filter.addExtension(".txt",true);
    //filter.setDescription("Text Files(.txt)");
    // chooser.setFileFilter(filter);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    //chooser.setMultiSelectionEnabled(true);
    int returnVal = chooser.showOpenDialog(client);
    if(returnVal ==JFileChooser.APPROVE_OPTION)
    //File fp[]=chooser.getSelectedFiles();
    File fp[]=new File[1];
    fp[0]=chooser.getSelectedFile();
    int i=0;
    while(i<fp.length)
    try{
    File file=fp[0];
    Icon icon=chooser.getIcon(file);
    FileInputStream fstream=new FileInputStream(file);
    int filedata=(new Double(file.length())).intValue();
    byte bytes[]=new byte[filedata];
    fstream.read(bytes);
    files.put(file,bytes);
    catch(Exception e){dialog.showMessageDialog(client,e.toString(),"Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
    return; }
    i++;
    java.util.List fileList=Arrays.asList(fp);
    addAttach(fileList);
    if(s.equals("Send"))
    try{
    if(toalias==null)
    dialog.showMessageDialog(client,"Select the Recepient First!!","Error:ChatApplication",JOptionPane.ERROR_MESSAGE);
    return;
    if(toalias!=null && togroup!=null && (!toalias.equals(fromalias)))
    // server.sendMessage(textArea1.getText(),files,toalias,togroup,fromalias,fromgroup);
    textArea1.setText("");
    catch(Exception e)
    e.printStackTrace();
    }//if ends
    class WindowEventHandler extends WindowAdapter{
    public void windowClosing(WindowEvent ev){
    try{
    //server.disconnect(client);
    client.getSound(3);
    // UnicastRemoteObject.unexportObject(client,true);
    catch(Exception e){System.out.println(e.toString());}
    dispose();
    private class onshutdown extends Thread{
    public void run(){
    try{
    //server.disconnect(client);
    //UnicastRemoteObject.unexportObject(client,true);
    catch(Exception e){}
    }//run ends
    I hope this helps,
    Denis

  • Can some one please tell me what is the problem in the below pl/sql block

    Hi, I have problem with the following pl/sql block, I need this with bulk operation.
    -- Assume the following scenario, we are validating dept (master) and emp(child) which are my temporary tables and updating the status back to
    -- dept ( for all the validation errors, even if we have any validation at child  it has to update the header record with error message),
    -- upon successful validation insert the data into dept3, and emp3 interms of batches
    -- I have give the sample example with dept and emp, but i have around 10 million records which has around 30-40 validations,
    -- I would like to process them in terms of batches using bulk collection as this would do fast processing
    -- Can some one please tell me how to insert them in terms of bulk with every set of 1000 records in each batch in this example,for every set of 1000 records
    -- i need update batch id with unique number in dept table
    -- with current data i can have 50 batches , I need to pass, deptno as parameter to my emp cursor. 
    -- can some one please tell me how to make this validation and insertion more efficient. so that while inserting the data for every batch it should insert batch id
    -- Tried with LIMIT clause as well but not working
    -- I am correcting the code as per your comments Request you to please suggest me so that I can correct , I am new to PL/sql, started learning now.
    step - 1:
    CREATE TABLE DEPT
           (DEPTNO NUMBER(6) primary key,
            DNAME VARCHAR2(25),
            LOC VARCHAR2(23),
            batch_id number );
    INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK', null);
    INSERT INTO DEPT VALUES (20, 'RESEARCH',   'DALLAS', null);
    INSERT INTO DEPT VALUES (30, 'SALES',      'CHICAGO', null);
    INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON', null);
    step - 2:
    declare
    begin
    for i in 1..50000 loop
    insert into dept values(40+i, 'OPERATIONS'||i,'BOSTON'||i, null);
    end loop;
    commit;
    exception
    when others then
    dbms_output.put_line('Exception occured:'||SQLERRM);
    end;
    step - 3:
    create sequence emp_seq start with 1 increment by 1;
    step - 4:
    CREATE TABLE EMP
           (EMPNO NUMBER(15) NOT NULL primary key,
            ENAME VARCHAR2(20),
            JOB VARCHAR2(20),
            MGR NUMBER(4),
            HIREDATE DATE,
            SAL NUMBER(7, 2),
            COMM NUMBER(7, 2),
            DEPTNO NUMBER(6));
    INSERT INTO EMP VALUES
            (7369, 'SMITH',  'CLERK',     7902,
            TO_DATE('17-DEC-1980', 'DD-MON-YYYY'),  800, NULL, 20);
    INSERT INTO EMP VALUES
            (7499, 'ALLEN',  'SALESMAN',  7698,
            TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600,  300, 30);
    INSERT INTO EMP VALUES
            (7521, 'WARD',   'SALESMAN',  7698,
            TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250,  500, 30);
    INSERT INTO EMP VALUES
            (7566, 'JONES',  'MANAGER',   7839,
            TO_DATE('2-APR-1981', 'DD-MON-YYYY'),  2975, NULL, 20);
    INSERT INTO EMP VALUES
            (7654, 'MARTIN', 'SALESMAN',  7698,
            TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);
    INSERT INTO EMP VALUES
            (7698, 'BLAKE',  'MANAGER',   7839,
            TO_DATE('1-MAY-1981', 'DD-MON-YYYY'),  2850, NULL, 30);
    INSERT INTO EMP VALUES
            (7782, 'CLARK',  'MANAGER',   7839,
            TO_DATE('9-JUN-1981', 'DD-MON-YYYY'),  2450, NULL, 10);
    INSERT INTO EMP VALUES
            (7788, 'SCOTT',  'ANALYST',   7566,
            TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
    INSERT INTO EMP VALUES
            (7839, 'KING',   'PRESIDENT', NULL,
            TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);
    INSERT INTO EMP VALUES
            (7844, 'TURNER', 'SALESMAN',  7698,
            TO_DATE('8-SEP-1981', 'DD-MON-YYYY'),  1500, NULL, 30);
    INSERT INTO EMP VALUES
            (7876, 'ADAMS',  'CLERK',     7788,
            TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);
    INSERT INTO EMP VALUES
            (7900, 'JAMES',  'CLERK',     7698,
            TO_DATE('3-DEC-1981', 'DD-MON-YYYY'),   950, NULL, 30);
    INSERT INTO EMP VALUES
            (7902, 'FORD',   'ANALYST',   7566,
            TO_DATE('3-DEC-1981', 'DD-MON-YYYY'),  3000, NULL, 20);
    INSERT INTO EMP VALUES
            (7934, 'MILLER', 'CLERK',     7782,
            TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);
    commit;
    step :- 5
    declare
    cursor c1 is select * from dept;
    k number:=0;
    m number:=0;
    begin
    for i in  c1 loop
    k:=k+1;
    --dbms_output.put_line('k:'||k);
    --dbms_output.put_line('i.deptno:'||i.deptno);
    m:=0;
    for j in 1..5 loop
    m:=m+1;
    --dbms_output.put_line('m:'||m);
    --dbms_output.put_line('i.deptno:'||i.deptno);
    insert into emp values
            (9000+emp_seq.nextval, 'SMITH'||'_'||emp_seq.currval,  'CLERK'||'_'||emp_seq.currval,     7902,
            TO_DATE('17-DEC-1980', 'DD-MON-YYYY'),  800, NULL, i.deptno);
    end loop;
    end loop;
    commit;
    exception
    when others then
    dbms_output.put_line('Exception occured:'||sqlerrm);
    end;
    step :-6
    create table dept3 as select * from dept where 1=2;
    create table emp3 as select * from emp where 1=2;
    alter table dept add object_id number;
    alter table dept add status varchar(20);
    alter table dept add err_msg varchar2(200);
    alter table emp add object_id number;
    -- I have not included the alter statements in the inital creation because i dont want them to insert into dept3 and emp3
    CREATE OR REPLACE
    PACKAGE test_b
    AS
      g_batch_id NUMBER;
      PROCEDURE emp_ins(
          p_EMPNO    NUMBER,
          p_ENAME    VARCHAR2,
          p_JOB      VARCHAR2,
          p_MGR      NUMBER,
          p_HIREDATE DATE,
          p_SAL      NUMBER,
          p_COMM     NUMBER,
          p_DEPTNO   NUMBER);
      PROCEDURE dept_ins(
          p_DEPTNO NUMBER,
          p_dname  VARCHAR2 ,
          p_LOC    VARCHAR2,
          p_batch  NUMBER);
      PROCEDURE validate_prc;
      PROCEDURE main;
    TYPE dept_t
    IS
      TABLE OF dept%ROWTYPE;
      hdr_tbl dept_t;
    TYPE emp_t
    IS
      TABLE OF emp%ROWTYPE;
      line_tbl emp_t;
    TYPE dept_i_t
    IS
      TABLE OF dept3%ROWTYPE;
      hdr_ins_tbl dept_i_t;
    TYPE emp_i_t
    IS
      TABLE OF emp3%ROWTYPE;
      line_ins_tbl emp_i_t;
    END;
    -- pacakge body
    CREATE OR REPLACE
    PACKAGE body test_b
    AS
    PROCEDURE emp_ins(
        p_EMPNO    NUMBER,
        p_ENAME    VARCHAR2,
        p_JOB      VARCHAR2,
        p_MGR      NUMBER,
        p_HIREDATE DATE,
        p_SAL      NUMBER,
        p_COMM     NUMBER,
        p_DEPTNO   NUMBER)
    IS
    BEGIN
      INSERT
      INTO EMP3
          EMPNO ,
          ENAME ,
          JOB ,
          MGR ,
          HIREDATE ,
          SAL ,
          COMM ,
          DEPTNO
        VALUES
          P_EMPNO ,
          P_ENAME ,
          P_JOB ,
          P_MGR ,
          P_HIREDATE ,
          P_SAL ,
          P_COMM ,
          P_DEPTNO
    EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('EXCEPTION AT EMP INSERT'||SQLERRM);
    END;
    PROCEDURE dept_ins
        p_DEPTNO NUMBER,
        p_dname  VARCHAR2 ,
        p_LOC    VARCHAR2,
        p_batch  NUMBER
    IS
    BEGIN
      INSERT
      INTO DEPT3
          DEPTNO ,
          DNAME ,
          LOC ,
          batch_id
        VALUES
          p_DEPTNO ,
          p_DNAME ,
          p_LOC ,
          p_batch
    EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('EXCEPTION AT DEPT INSERT'||SQLERRM);
    END ;
    PROCEDURE validate_prc
    IS
      CURSOR c1
      IS
        SELECT * FROM dept WHERE status IS NULL ;--AND rownum <25;
      CURSOR c2(p_dept NUMBER )
      IS
        SELECT * FROM emp WHERE deptno=p_dept;
      e_validation EXCEPTION;
    BEGIN
      OPEN c1;
      LOOP
        FETCH c1 BULK COLLECT INTO hdr_tbl limit 5000;
        SELECT emp_seq.nextval INTO g_batch_id FROM dual;
        EXIT
      WHEN hdr_tbl.count = 0;
        dbms_output.put_line('batch'||g_batch_id);
      END LOOP;
      CLOSE c1;
      dbms_output.put_line('C1 closed');
      --------- Loading data into the inv line table type -------------------------------
      FOR i IN 1 .. hdr_tbl.count
      LOOP
        dbms_output.put_line('started validation');
        -- do header level validations
        IF hdr_tbl(i).dname  IS NULL THEN
          hdr_tbl(i).status  := 'ERROR';
          hdr_tbl(i).err_msg :=',DNAME is null';
        END IF;
        OPEN c2(hdr_tbl(i).deptno);
        LOOP
          FETCH c2 BULK COLLECT INTO line_tbl;
          -- EXIT WHEN c2%NOTFOUND;
        END LOOP;
        CLOSE c2;
        FOR j IN 1 .. line_tbl.count
        LOOP
          -- do line validations
          IF line_tbl(j).ename IS NULL THEN
            hdr_tbl(i).status  := 'ERROR';
            hdr_tbl(i).err_msg :=',ENAME is null';
          END IF;
          BEGIN
            FORALL j IN line_tbl.FIRST .. line_tbl.LAST
            SAVE EXCEPTIONS
            UPDATE EMP
            SET object_id =3
              -- I have multiple columns to update based on validations
            WHERE deptno =hdr_tbl(i).deptno------------
            AND empno    =line_tbl (j).empno;
            COMMIT;
            line_tbl.DELETE;
            dbms_output.put_line( 'Successfully updated emp temp table.');
          EXCEPTION
          WHEN OTHERS THEN
            ROLLBACK;
            dbms_output.put_line( 'Error while updating line temp table. ' || sqlerrm );
            FOR j IN 1 .. sql%BULK_EXCEPTIONS.COUNT
            LOOP
              DBMS_OUTPUT.put_line(' occurred during line temp table updation ' || sql%BULK_EXCEPTIONS(i).ERROR_INDEX );
            END LOOP;
            raise e_validation;
          END;
        END LOOP; -- j
        --CLOSE c2;
        IF hdr_tbl(i).err_msg IS NULL THEN
          hdr_tbl (i).status  := 'VALID';
          hdr_tbl (i).err_msg := NULL;
        END IF;
        -- even if I have line validation failed I have to update header status and erorr msg
        BEGIN
          FORALL i IN hdr_tbl.FIRST .. hdr_tbl.LAST
          SAVE EXCEPTIONS
          UPDATE DEPT
          SET object_id =4,
            status      = hdr_tbl (i).status,
            err_msg     = hdr_tbl (i).err_msg
            --  batch_id =
            -- I have multiple columns to update based on validations
          WHERE deptno = hdr_tbl (i).deptno
          AND status  IS NULL; ------------
          COMMIT;
          hdr_tbl.DELETE;
          dbms_output.put_line( 'Successfully updated dept temp table.');
          --close c1;
        EXCEPTION
        WHEN OTHERS THEN
          ROLLBACK;
          dbms_output.put_line( 'Error while updating hdr temp table. ' || sqlerrm );
          FOR i IN 1 .. sql%BULK_EXCEPTIONS.COUNT
          LOOP
            DBMS_OUTPUT.put_line(' occurred during line temp table updation ' || sql%BULK_EXCEPTIONS(i).ERROR_INDEX );
          END LOOP;
          raise e_validation;
        END;
      END LOOP; --i
    EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('EXCEPTION AT validate'||SQLERRM);
    END ;
    PROCEDURE main
    IS
      CURSOR dept_ins_cur
      IS
        SELECT * FROM dept WHERE status='VALID';
      CURSOR emp_ins_cur(p_deptno NUMBER)
      IS
        SELECT * FROM emp WHERE deptno= p_deptno;
    BEGIN
      validate_prc;
      OPEN dept_ins_cur;
      LOOP
      FETCH dept_ins_cur BULK COLLECT INTO hdr_ins_tbl limit 1000
      EXIT
      WHEN dept_ins_cur%NOTFOUND;
      END LOOP;
      CLOSE dept_ins_cur;
      --------- Loading data into the inv line table type -------------------------------
      FOR i IN 1 .. hdr_tbl.count
      loop
      dept_ins(hdr_ins_tbl(i).deptno ,
      hdr_ins_tbl(i).DNAME ,
      hdr_ins_tbl(i).LOC , emp_seq.nextval);
      commit;
      OPEN emp_ins_cur(hdr_ins_tbl(i).deptno);
      LOOP
      FETCH emp_ins_cur BULK COLLECT INTO line_ins_tbl;
      --EXIT WHEN emp_ins_cur%NOTFOUND;
      END LOOP;
      CLOSE emp_ins_cur;
      for j in 1..line_ins_tbl.count loop
      emp_ins(line_ins_tbl(j).EMPNO ,
      line_ins_tbl(j).ENAME ,
      line_ins_tbl(j).JOB ,
      line_ins_tbl(j).MGR ,
      line_ins_tbl(j).HIREDATE ,
      line_ins_tbl(j).SAL ,
      line_ins_tbl(j).comm ,
      line_ins_tbl(j).DEPTNO );
      end loop;
      end loop;
      commit;
      BEGIN
      forall i IN hdr_ins_tbl.first .. hdr_ins_tbl.last
      SAVE exceptions
      UPDATE dept
      SET status   = 'INSERTED',
      err_msg  = null
      WHERE deptno=hdr_ins_tbl (i).deptno
      AND status   = 'VALID';
      COMMIT;
      hdr_ins_tbl.delete;
      dbms_output.put_line( 'inserting into temp tables.');
      EXCEPTION
      WHEN OTHERS THEN
      rollback;
      end;
    EXCEPTION
    WHEN OTHERS THEN
      dbms_output.put_line('exception in main' ||SQLERRM);
    END ;
    END;
    Thanks in advance...
    Message was edited by: 888025

    Hi, I have problem with the following pl/sql block
    Well, as Hoek already said, that is the understatement of the century.
    I can't be absolutely certain but I think that set of DDL and code that you posted has just about every possible error and design issue that there is! It would make an excellent addition to BluShadow's FAQs an an example of what NOT to do.
    I don't think it is even possible to 'fix the basics first' as Hoek suggested. IMHO the first step needs to be to create a functional requirements document (FRD) that explains in detail WHAT needs to be done. That doc should also contain info about how any errors/recovery/restart is to be handled. It is premature to try to implement ANY solution without first knowing what is needed functionally.
    Once the FRD is done you should do a walk-through based on your current architecture and sample data to make sure that the document really covers ALL of the steps that need to be performed and that it adequately explains how to deal with any processing or data issues that might arise.
    The next document you need is the TRD - Technical Requirements Doc that covers the different technical implementions of the FRD that can be done and the advantages/disadvantages of each.
    Then you can start working on a prototype.
    1. The DDL you posted isn't coherent - there are CREATE table statements and then later ALTER statements that add additional columns. There doesn't appear to be any reason for not including ALL of the columns in the CREATE table statement.
    2. You are using PL/SQL types instead of SQL types. That makes it impossible to use those types in SQL statements and makes it much more difficult to test since it is much easier to test a query in SQL (e.g. using sql*plus) that to embed the query in PL/SQL.
    3. You are defining the same type twice but giving it different names.
    TYPE dept_t
       IS
          TABLE OF dept%ROWTYPE
             INDEX BY binary_integer;
    TYPE dept_i_t
       IS
          TABLE OF dept%ROWTYPE
             INDEX BY binary_integer;
    Those are both based on the same DEPT table! Why the duplication?
    Also you are using associative arrays instead of just using nested tables. Get rid of the INDEX BY clause.
    4. You have some serious architectural and data model issues
    -- Assume the following scenario, we are validating dept (master) and emp(child) which are my temporary tables and updating the status back to
    -- dept ( for all the validation errors, even if we have any validation at child  it has to update the header record with error message),
    Why would you do that? You say 'it has to update the header record ...'. Says who? That is just one indication that you are trying to implement a 'solution' before you have adequately defined the 'problem'.
    Typically you would NOT alter any of the data tables; any validation errors/issues would get inserted into a table specifically designed to hold/log those issues. That table would contain key field values to correlate with the source of the error.
    Those 'master' and 'child' entities are two SEPARATE things. Issues with a 'master' row have NOTHING to do with any possible child rows.
    And issues with a 'child' row have NOTHING to do with any possible master rows. The ONLY connection between 'child' and 'master' is the foreign key that correlates them.
    So you don't necessarily have to validate the 'child' rows in sync with their 'master' row. In many cases you would have a procedure that performs validation of the entire set of 'master' rows and log those issues/problems. You would use a different procedure to validate the entire set of 'child' rows and log their issues.
    Those validation procedures can often work with ALL of the data using SQL statements instead of bulk processing.
    5. You are using loop constructs that are not valid for the type of processing you are using
    LOOP
        FETCH c1 BULK COLLECT INTO hdr_tbl;
        EXIT
      WHEN c1%NOTFOUND;
      END LOOP;
    There can be NO exit since the bulk collect with either get EVERYTHING or NOTHING. Possibly that is just a holdover from your attempt to use the LIMIT clause but you removed that clause from the FETCH; I don't know.
    There is so much wrong with what you posted it is really rather pointless to try to 'fix' it.
    I suggest you start over and clarify and DOCUMENT the actual requirements without prejudice about the solution that someone seems to want to force on you.

  • Macbook slow and icons lag and fan noise and windows performance normal but the fan noise still there.Please tell me what is the problem

    Hi , i have late 2011 model of 13 inch macbook pro. Installled mountain lion . Around 200 gb of free space. Now when i start my mac os the icons lag and it takes time to open up even scrolling the mouse you can see it drag and also the fan runs at high rpm .The cpu processesor runs at peak. When i switch on the windows the fan noise still there but the performance is good.Please advice me what might be the problem and what shall i do to solve it.

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It won’t solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    Third-party system modifications are a common cause of usability problems. By a “system modification,” I mean software that affects the operation of other software — potentially for the worse. The following procedure will help identify which such modifications you've installed. Don’t be alarmed by the complexity of these instructions — they’re easy to carry out and won’t change anything on your Mac. 
    These steps are to be taken while booted in “normal” mode, not in safe mode. If you’re now running in safe mode, reboot as usual before continuing. 
    Below are instructions to enter some UNIX shell commands. The commands are harmless, but they must be entered exactly as given in order to work. If you have doubts about the safety of the procedure suggested here, search this site for other discussions in which it’s been followed without any report of ill effects. 
    Some of the commands will line-wrap or scroll in your browser, but each one is really just a single line, all of which must be selected. You can accomplish this easily by triple-clicking anywhere in the line. The whole line will highlight, and you can then copy it. The headings “Step 1” and so on are not part of the commands. 
    Note: If you have more than one user account, Step 2 must be taken as an administrator. Ordinarily that would be the user created automatically when you booted the system for the first time. The other steps should be taken as the user who has the problem, if different. Most personal Macs have only one user, and in that case this paragraph doesn’t apply. 
    Launch the Terminal application in any of the following ways: 
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.) 
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens. 
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid. 
    When you launch Terminal, a text window will open with a line already in it, ending either in a dollar sign (“$”) or a percent sign (“%”). If you get the percent sign, enter “sh” and press return. You should then get a new line ending in a dollar sign. 
    Step 1 
    Triple-click the line of text below on this page to select it:
    kextstat -kl | awk '!/com\.apple/{printf "%s %s\n", $6, $7}' | open -f -a TextEdit 
    Copy the selected text to the Clipboard by pressing the key combination command-C. Then click anywhere in the Terminal window and paste (command-V). A TextEdit window will open with the output of the command. If the command produced no output, the window will be empty. Post the contents of the TextEdit window (not the Terminal window), if any — the text, please, not a screenshot. You can then close the TextEdit window. The title of the window doesn't matter, and you don't need to post that. No typing is involved in this step.
    Step 2 
    Repeat with this line:
    { sudo launchctl list | sed 1d | awk '!/0x|com\.(apple|openssh|vix)|org\.(amav|apac|cups|isc|ntp|postf|x)/{print $3}'; sudo defaults read com.apple.loginwindow LoginHook; sudo crontab -l; } 2> /dev/null | open -f -a TextEdit 
    This time you'll be prompted for your login password, which you do have to type. Nothing will be displayed when you type it. Type it carefully and then press return. You may get a one-time warning to be careful. Heed that warning, but don't post it. If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator. 
    Note: If you don’t have a login password, you’ll need to set one before taking this step. If that’s not possible, skip to the next step. 
    Step 3
    { launchctl list | sed 1d | awk '!/0x|com\.apple|org\.(x|openbsd)/{print $3}'; crontab -l 2> /dev/null; } | open -f -a TextEdit 
    Step 4
    ls -1A /e*/{la,mach}* {,/}L*/{Ad,Compon,Ex,Fram,In,Keyb,La,Mail/Bu,P*P,Priv,Qu,Scripti,Servi,Spo,Sta}* L*/Fonts .la* 2> /dev/null | open -f -a TextEdit  
    Important: If you formerly synchronized with a MobileMe account, your me.com email address may appear in the output of the above command. If so, anonymize it before posting. 
    Step 5
    osascript -e 'tell application "System Events" to get name of every login item' | open -f -a TextEdit 
    Remember, steps 1-5 are all copy-and-paste — no typing, except your password. Also remember to post the output. 
    You can then quit Terminal.

  • Custom tables create in Apps schema ( What are the problems with this?)wwww

    Hello all,
    I'm a dba in a new environment where a number of custom schemas are being created in the apps schema. I know this is not considered Oracle's best practice and I would like to make some recommendations for a change. Before doing so, I would like to know the problems that are associated with custom tables living in the apps schema. We are currently on 11.5.10.2 on AIX. Also, if someone can point me to any "Official" customization standard or Oracle documention where I can backup my case it would be greatly appreciated.
    Thanks in advance,

    Hi,
    Please see this thread.
    Custom application implemented in E-bussiness Suite
    Re: Custom application implemented in E-bussiness Suite
    Regards,
    Hussein

  • What's the problem with this CC stuff?

    Since CC is available I only have trouble with all this stuff. I'm on OSX ML and there seems to be no change to install anything of the new stuff. CC app desktop- failed to install. When I use AAM, the CC apps are available, but after downloading I get an installation failure (15). I've tried anything discussed in this community, but nothing worked. So why there are so many problems with CC? Since I pay over 60 Euros each month, I would like to use the promised applications. ADOBE, please supply a reliable solution for all operating systems without the need of erase data, rename folders or anything else. Thanks in advance.

    1hausl1 I would recommend you contact our support team and work with them directly.  You can contact our chat support at http://adobe.ly/yxj0t6.

Maybe you are looking for