Results 1 to 3 of 3

Thread: Hi friends

  1. #1
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Thumbs up Hi friends

    I am doing my project in data mining.I am using the following code for feature selection.while executing it displays "SQl exception" -Result is closed.I don't know what is the problem in it.I have closed all the connections.
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import javax.swing.table.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.metal.*;
    import com.sun.java.swing.plaf.motif.*;
    import com.sun.java.swing.plaf.windows.*;

    import java.util.*;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    public class decisionTree extends JFrame
    {
    JPanel p1 = new JPanel();
    boolean inAnApplet = true;
    final boolean shouldFill = true;
    final boolean shouldWeightX = true;
    Container contentPane = getContentPane();
    JTabbedPane tabbedPane = new JTabbedPane();
    MetalLookAndFeel metalLF = new MetalLookAndFeel();
    MotifLookAndFeel motifLF = new MotifLookAndFeel();
    WindowsLookAndFeel windowsLF = new WindowsLookAndFeel();
    //int tp2=0,tp22=0,fp22=0,tn2=0,tn22=0,fn22=0,fp2=0,fn2= 0,tc2=0,tc22=0;
    //int tp23,tn23,fp23,fn23,tc23;
    String datana[]= {"a1","a2","a3","a4","a5","a6"};
    public static void main(String args[])
    {
    decisionTree app = new decisionTree();
    }
    public decisionTree()
    {
    // Declare Title to my Application
    super("Feature Subsets Finding");
    setup();
    pack();
    //addWindowListener(new WindowEventHandler());
    show();
    }


    void setup()
    {
    setupMenuBar(); //Call "setupMenuBar()" to Build the Exit Menu
    showpane1(); //Call some method to Build the Exit Menu
    showpane2();
    showpane3();
    contentPane.add(tabbedPane, BorderLayout.CENTER);
    }

    void setupMenuBar()
    {
    MenuBar menuBar = new MenuBar();
    // Main Menu will be "File"
    Menu fileMenu = new Menu("File");
    // Sub menu under it will be "Exit"
    MenuItem fileExit = new MenuItem("Exit");
    // Handle this submenu item clcik event to Exit
    fileExit.addActionListener(new MenuItemHandler());
    fileMenu.add(fileExit);
    menuBar.add(fileMenu);
    Menu styleMenu = new Menu("Style");
    MenuItem styleWin = new MenuItem("Windows");
    styleWin.addActionListener(new MenuItemHandler());
    styleMenu.add(styleWin);
    MenuItem styleMotif = new MenuItem("Motif");
    styleMotif.addActionListener(new MenuItemHandler());
    styleMenu.add(styleMotif);
    MenuItem styleMetal = new MenuItem("Metal");
    styleMetal.addActionListener(new MenuItemHandler());
    styleMenu.add(styleMetal);
    menuBar.add(styleMenu);
    setMenuBar(menuBar);
    }
    void showpane1()
    {
    JLabel l1=new JLabel("Taken training Data samples are");
    p1.add(l1);
    DefaultTableModel dt=new DefaultTableModel();
    JTable jt=new JTable(dt);
    Object[] data=new Object[10];


    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection cp=DriverManager.getConnection("jdbc:odbc:dataset" ,"","");
    Statement st=cp.createStatement();

    ResultSet rs=st.executeQuery("select * from monk3");
    ResultSetMetaData rt=rs.getMetaData();

    int row=rt.getColumnCount();
    for(int j=1;j<=row;j++)
    {

    dt.addColumn(rt.getColumnName(j));
    }

    while(rs.next())
    {
    for(int j=0;j<row;j++)
    {
    data[j]=rs.getString(j+1);
    }
    dt.addRow(data);
    }
    JTableHeader header = jt.getTableHeader();
    header.setBackground(Color.yellow);
    JScrollPane pane = new JScrollPane(jt);
    //Container cp1=getContentPane();
    p1.add(pane);
    rs.close();
    st.close();
    cp.close();


    }

    catch(Exception e)
    {

    JOptionPane.showMessageDialog((Component)null,"IDn o Already Exists","Error!!! ",JOptionPane.ERROR_MESSAGE);
    }

    tabbedPane.addTab("Training data",p1);
    }
    void showpane2()
    {
    JPanel p2 = new JPanel();
    double gains[]=new double[10];
    int ct=0;
    double f1,f2,inf_gain,gain_f1,gain_f2,gain_f3,gain_f4,gai n_f5,gain_f6;
    String[] an={"a1","a2","a3","a4","a5","a6"};

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection cp=DriverManager.getConnection("jdbc:odbc:dataset" ,"","");
    Statement st=cp.createStatement();
    int total=0,c1=0,c2=0,c=0;

    //Information gain for splitting criterion
    ResultSet rt=st.executeQuery("select count(*) from monk3");
    while(rt.next())
    total=rt.getInt(1);

    ResultSet rs=st.executeQuery("select count(*) from monk3 where class='1'");
    while(rs.next())
    c1=rs.getInt(1);

    ResultSet rs1=st.executeQuery("select count(*) from monk3 where class='0'");
    while(rs1.next())
    c2=rs1.getInt(1);

    System.out.println(total+"and"+c1+"and"+c2);

    f1=((double)c1/(double)total);
    f2=((double)c2/(double)total);
    inf_gain=((-f1*(Math.log(f1)/Math.log(2)))+(-f2*(Math.log(f2)/Math.log(2))));


    //computing Information gain for each attribute
    //compute Information gain for first attribute { headshape : round,square,octagen}

    ResultSet hs_r=st.executeQuery("select count(*) from monk3 where a1='1' and class='1'");
    while(hs_r.next())
    c1=hs_r.getInt(1);


    ResultSet hs_rn=st.executeQuery("select count(*) from monk3 where a1='1' and class='0'");

    double t1,t2,t3;
    while(hs_rn.next())
    c2=hs_rn.getInt(1);


    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c1+c2);
    t3=(double)c2/(double)(c1+c2);
    double rd=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_rd=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet hs_s=st.executeQuery("select count(*) from monk3 where a1='2' and class='1'");
    while(hs_s.next())
    c1=hs_s.getInt(1);

    ResultSet hs_sn=st.executeQuery("select count(*) from monk3 where a1='2' and class='0'");
    while(hs_sn.next())
    c2=hs_sn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double sr=t1*(((-t2)*(Math.log(t2)/Math.log(2.0))));//-((t3)*(Math.log(t3)/Math.log(2.0))));
    double split_sr=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet hs_o=st.executeQuery("select count(*) from monk3 where a1='3' and class='1'");
    while(hs_o.next())
    c1=hs_o.getInt(1);

    ResultSet hs_on=st.executeQuery("select count(*) from monk3 where a1='3' and class='0'");
    while(hs_on.next())
    c2=hs_on.getInt(1);
    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double on=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_on=((-t1)*(Math.log(t1)/Math.log(2.0)));

    double heads=rd+sr+on;
    double gain_heads=inf_gain-heads;
    double split_heads=split_rd+split_sr+split_on;
    gain_f1=gain_heads/split_heads;
    //compute information requirement for second attribute{body shape:round,square,octagen}
    ResultSet bs_t=st.executeQuery("select count(*) from monk3 where a2='1'") ;
    while(bs_t.next())
    c=bs_t.getInt(1);
    //tc2=c;

    ResultSet bs_r=st.executeQuery("select count(*) from monk3 where a2='1' and class='1'");
    while(bs_r.next())
    c1=bs_r.getInt(1);
    //tp2=c1;
    //fn2=c1;

    ResultSet bs_rn=st.executeQuery("select count(*) from monk3 where a2='1' and class='0'");
    while(bs_rn.next())
    c2=bs_rn.getInt(1);
    //tn2=c2;
    //fp2=c2;

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c1+c2);
    t3=(double)c2/(double)(c1+c2);
    double rd1=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_rd1=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet bs_tt=st.executeQuery("select count(*) from monk3 where a2='2'") ;
    while(bs_tt.next())
    c=bs_tt.getInt(1);
    //tc22=c;
    ResultSet bs_s=st.executeQuery("select count(*) from monk3 where a2='2' and class='1'");
    while(bs_s.next())
    c1=bs_s.getInt(1);
    //tp22=c1;
    //fn22=c1;

    ResultSet bs_sn=st.executeQuery("select count(*) from monk3 where a2='2' and class='0'");
    while(bs_sn.next())
    c2=bs_sn.getInt(1);
    //tn22=c2;
    //fp22=c2;

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double sr1=t1*(((-t2)*(Math.log(t2)/Math.log(2.0))));//-((t3)*(Math.log(t3)/Math.log(2.0))));
    double split_sr1=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet bs_ot=st.executeQuery("select count(*) from monk3 where a2='3'") ;
    while(bs_tt.next())
    c=bs_tt.getInt(1);
    //tc23=c;

    ResultSet bs_o=st.executeQuery("select count(*) from monk3 where a2='3' and class='1'");
    while(bs_o.next())
    c1=bs_o.getInt(1);
    //tp23=c1;
    //fn23=c1;

    ResultSet bs_on=st.executeQuery("select count(*) from monk3 where a2='3' and class='0'");
    while(bs_on.next())
    c2=bs_on.getInt(1);
    //tn23=c2;
    //fn23=c2;

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double on1=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_on1=((-t1)*(Math.log(t1)/Math.log(2.0)));

    double bodys=rd1+sr1+on1;
    double gain_bodys=inf_gain-bodys;
    double split_bodys=split_rd1+split_sr1+split_on1;
    gain_f2=gain_bodys/split_bodys;

    //compute information requirement for third attribute {is_smiling : yes,no}
    ResultSet is_sy=st.executeQuery("select count(*) from monk3 where a3='1' and class='1'");
    while(is_sy.next())
    c1=is_sy.getInt(1);

    ResultSet is_syn=st.executeQuery("select count(*) from monk3 where a3='1' and class='0'");
    while(is_syn.next())
    c2=is_syn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double smiley=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_smiley=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet is_sn=st.executeQuery("select count(*) from monk3 where a3='2' and class='1'");
    while(is_sn.next())
    c1=is_sn.getInt(1);

    ResultSet is_snn=st.executeQuery("select count(*) from monk3 where a3='2' and class='0'");
    while(is_snn.next())
    c2=is_snn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double smilen=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_smilen=((-t1)*(Math.log(t1)/Math.log(2.0)));

    double smile=smiley+smilen;
    double gain_smil=inf_gain-smile;
    double split_smil=split_smiley+split_smilen;
    gain_f3=gain_smil/split_smil;

    //compute information requirement for fourth attribute {holding : sword,ballon,flag}
    ResultSet ho_s=st.executeQuery("select count(*) from monk3 where a4='1' and class='1'");
    while(ho_s.next())
    c1=ho_s.getInt(1);

    ResultSet ho_sn=st.executeQuery("select count(*) from monk3 where a4='1' and class='0'");
    while(ho_sn.next())
    c2=ho_sn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double holds=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_holds=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet ho_b=st.executeQuery("select count(*) from monk3 where a4='2' and class='1'");
    while(ho_b.next())
    c1=ho_b.getInt(1);

    ResultSet ho_bn=st.executeQuery("select count(*) from monk3 where a4='2' and class='0'");
    while(ho_bn.next())
    c2=ho_bn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double holdb=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_holdb=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet ho_f=st.executeQuery("select count(*) from monk3 where a4='3' and class='1'");
    while(ho_f.next())
    c1=ho_f.getInt(1);

    ResultSet ho_fn=st.executeQuery("select count(*) from monk3 where a4='3' and class='0'");
    while(ho_fn.next())
    c2=ho_fn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double holdf=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_holdf=((-t1)*(Math.log(t1)/Math.log(2.0)));


    double holding=holds+holdb+holdf;
    double gain_hold=inf_gain-holding;
    double split_hold=split_holds+split_holdb+split_holdf;
    gain_f4=gain_hold/split_hold;

    //compute information requirement for fifth attribute{jacket color: red,green,yellow,blue}
    ResultSet jc_r=st.executeQuery("select count(*) from monk3 where a5='1' and class='1'");
    while(jc_r.next())
    c1=jc_r.getInt(1);

    ResultSet jc_rn=st.executeQuery("select count(*) from monk3 where a5='1' and class='0'");
    while(jc_rn.next())
    c2=jc_rn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double jackcr=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_jackcr=((-t1)*(Math.log(t1)/Math.log(2.0)));


    ResultSet jc_y=st.executeQuery("select count(*) from monk3 where a5='2' and class='1'");
    while(jc_y.next())
    c1=jc_y.getInt(1);

    ResultSet jc_yn=st.executeQuery("select count(*) from monk3 where a5='2' and class='0'");
    while(jc_yn.next())
    c2=jc_yn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double jackcy=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_jackcy=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet jc_g=st.executeQuery("select count(*) from monk3 where a5='3' and class='1'");
    while(jc_g.next())
    c1=jc_g.getInt(1);

    ResultSet jc_gn=st.executeQuery("select count(*) from monk3 where a5='3' and class='0'");
    while(jc_gn.next())
    c2=jc_gn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double jackcg=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_jackcg=((-t1)*(Math.log(t1)/Math.log(2.0)));

    ResultSet jc_b=st.executeQuery("select count(*) from monk3 where a5='3' and class='1'");
    while(jc_b.next())
    c1=jc_b.getInt(1);

    ResultSet jc_bn=st.executeQuery("select count(*) from monk3 where a5='3' and class='0'");
    while(jc_bn.next())
    c2=jc_bn.getInt(1);

    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double jackcb=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_jackcb=((-t1)*(Math.log(t1)/Math.log(2.0)));

    double jacket=jackcr+jackcy+jackcg+jackcb;
    double gain_jacket=inf_gain-jacket;
    double split_jacket=split_jackcr+split_jackcy+split_jackc g+split_jackcb;
    gain_f5=gain_jacket/split_jacket;

    //compute information requirement for sixth attribute {hastie :yes,no}
    ResultSet has_t=st.executeQuery("select count(*) from monk3 where a6='1' and class='1'");
    while(has_t.next())
    c1=has_t.getInt(1);
    ResultSet has_tn=st.executeQuery("select count(*) from monk3 where a6='1' and class='0'");
    while(has_tn.next())
    c2=has_tn.getInt(1);
    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double hast=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_hast=((-t1)*(Math.log(t1)/Math.log(2.0)));


    ResultSet has_tiy=st.executeQuery("select count(*) from monk3 where a6='1' and class='1'");
    while(has_tiy.next())
    c1=has_tiy.getInt(1);

    ResultSet has_tin=st.executeQuery("select count(*) from monk3 where a6='1' and class='0'");
    while(has_tin.next())
    c2=has_tin.getInt(1);
    t1=((double)(c1+c2)/(double)total);
    t2=(double)c1/(double)(c2+c1);
    t3=(double)c2/(double)(c2+c1);
    double hasti=t1*(((-t2)*(Math.log(t2)/Math.log(2.0)))+((-t3)*(Math.log(t3)/Math.log(2.0))));
    double split_hasti=((-t1)*(Math.log(t1)/Math.log(2.0)));

    double hastie=hast+hasti;
    double gain_hastie=inf_gain-hastie;
    double split_hastie=split_hast+split_hasti;
    gain_f6=gain_hastie/split_hastie;


    gains[ct++]=gain_f1;
    gains[ct++]=gain_f2;
    gains[ct++]=gain_f3;
    gains[ct++]=gain_f4;
    gains[ct++]=gain_f5;
    gains[ct++]=gain_f6;


    int a,b;
    double temp;
    String temp1;

    for (a = 0; a < 6; ++a)
    {
    for (b = 0; b < 6; ++b)
    if(gains[b] < gains[b + 1])
    {
    temp = gains[b];
    gains[b] = gains[b + 1];
    gains[b + 1] = temp;

    temp1=an[b];
    an[b]=an[b+1];
    an[b+1]=temp1;
    }
    }

    DefaultTableModel dt=new DefaultTableModel();
    JTable jt=new JTable(dt);
    Object[] data1=new Object[10];
    String col[] = {"Attributes","Gain Ratios"};

    for(int j=0;j<2;j++)
    {

    dt.addColumn(col[j]);
    }



    int i=0;
    for(int j=0;j<6;j++)
    {
    data1[i++]=an[j];
    data1[i++]=gains[j];
    dt.addRow(data1);
    i=0;
    }

    JTableHeader header = jt.getTableHeader();
    header.setBackground(Color.yellow);
    JScrollPane pane = new JScrollPane(jt);
    p2.add(pane);


    rt.close();
    rs.close();
    rs1.close();
    hs_r.close();
    hs_rn.close();
    hs_s.close();
    hs_sn.close();
    hs_o.close();
    hs_on.close();
    bs_t.close();
    bs_r.close();
    bs_rn.close();
    bs_tt.close();
    bs_s.close();
    bs_sn.close();
    bs_ot.close();
    bs_o.close();
    bs_on.close();
    bs_ot.close();
    is_sy.close();
    is_syn.close();
    is_sn.close();
    is_snn.close();
    ho_s.close();
    ho_sn.close();
    ho_b.close();
    ho_bn.close();
    ho_s.close();
    ho_sn.close();
    jc_r.close();
    jc_rn.close();
    jc_y.close();
    jc_yn.close();
    jc_g.close();
    jc_gn.close();
    jc_b.close();
    jc_bn.close();
    has_t.close();
    has_tn.close();
    has_tiy.close();
    has_tin.close();

    st.close();
    cp.close();


    }
    catch(Exception e)
    {
    System.out.println(e);
    JOptionPane.showMessageDialog((Component)null,"SQL connection error","Error!!! ",JOptionPane.ERROR_MESSAGE);
    }

    tabbedPane.addTab("Gain Ratios",p2);
    //decisionacc t1=new decisionacc();
    //tabbedPane.addTab("SubsetAccuracy",t1);


    }

    /*public class decisionacc extends JPanel
    {
    JLabel l1,l3,l5,l7;
    int st=0;
    public static final int acc1 = 100;


    int acc,acc2,acc23;
    decisionacc()
    {
    setLayout(null);
    l1=new JLabel("Tuple we wish to classify:");
    add(l1);
    l1.setBounds(20,20,200,30);
    JTextField t1=new JTextField();
    JTextField t2=new JTextField();
    JTextField t3=new JTextField();
    JTextField t4=new JTextField();


    //l2=new JLabel(" {a2=1}");

    //add(l2);
    //l2.setBounds(20,40,400,30);

    if((tc2 == tp2)||(tc2== tn2))
    {
    System.out.println("All the subset value is in same class"+acc1);
    t1.setText(""+acc1);
    add(t1);
    }
    else
    {
    acc=(int)(((double)(tp2+tn2)/(double)(tp2+fp2+tn2+fn2))*100);

    System.out.println("accuracy" + acc);

    l3=new JLabel("Accuracy of classifier to predict the given tuple as classa using {a2=1}");
    add(l3);
    l3.setBounds(20,80,420,30);


    t1.setText(""+acc);
    add(t1);

    t1.setBounds(440,70,50,30);
    }
    //l4=new JLabel(" {a2=2}");

    //add(l4);
    //l4.setBounds(20,120,440,30);

    if((tc22 == tp22)||(tc22== tn22))
    {
    System.out.println("All the subset value is in same class"+acc1);
    t2.setText(""+acc1);
    add(t2);
    }
    else
    {
    acc2=(int)(((double)(tp22+tn22)/(double)(tp22+fp22+tn22+fn22))*100);
    System.out.println("accuracy" + acc2);

    l5=new JLabel("Accuracy of classifier to predict the given tuple as classa using {a2=2}");
    add(l5);
    l5.setBounds(20,140,480,30);

    t2.setText(""+acc2);
    add(t2);

    t2.setBounds(440,150,70,30);
    }
    //l6=new JLabel(" {a2=3}");

    //add(l6);
    //l6.setBounds(20,160,520,30);

    l7=new JLabel("Accuracy of classifier to predict the given tuple as classa using {a2=3}");
    add(l7);
    l7.setBounds(20,180,540,30);

    if((tc23 == tp23)||(tc23== tn23))
    {
    System.out.println("All the subset value is in same class"+acc1);
    t3.setText("" + acc1);
    add(t3);
    t3.setBounds(440,190,70,30);

    }
    else
    {
    acc23=(int)(((double)(tp23+tn23)/(double)(tp23+fp23+tn23+fn23))*100);

    System.out.println("accuracy" + acc23);


    t3.setText("" + acc23);
    add(t3);

    t3.setBounds(440,190,70,30);
    }

    }

    }*/
    void showpane3()
    {
    JPanel p3 = new JPanel();
    double acc;
    JLabel l1,l2,l3;
    int tp=0,tn=0,fp=0,fn=0;
    //double gains1[]=new double[10];
    //int ct=0;
    //double f1,f2,inf_gain,gain_f1,gain_f2,gain_f3,gain_f4,gai n_f5,gain_f6;
    //String[] an={"a1","a2","a3","a4","a5","a6"};

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection cp=DriverManager.getConnection("jdbc:odbc:dataset" ,"","");
    Statement st=cp.createStatement();


    l1=new JLabel("Tuple we wish to classify:");
    p3.add(l1);
    l1.setBounds(20,20,200,30);

    l2=new JLabel(" {a1=1}");

    p3.add(l2);
    l2.setBounds(20,40,400,30);


    ResultSet rt1=st.executeQuery("select count(*) from monk3 where a1='1' and class='1'");
    while(rt1.next())
    tp=rt1.getInt(1);
    fn=rt1.getInt(1);

    ResultSet rt0=st.executeQuery("select count(*) from monk3 where a1='1' and class='0'");
    while(rt0.next())
    tn=rt0.getInt(1);
    fp=rt0.getInt(1);
    System.out.println("true positive"+tp);
    System.out.println("true negative"+tn);
    System.out.println("false positive"+fp);
    System.out.println("false negative"+fn);

    acc=((double)(tp+tn)/(double)(tp+fp+tn+fn));

    System.out.println("accuracy" + acc);

    l3=new JLabel("Accuracy of classifier to predict the given tuple as classa using {a1}");
    p3.add(l3);
    JTextField t1=new JTextField();
    t1.setText(""+acc);
    p3.add(t1);

    t1.setBounds(440,80,50,30);
    rt1.close();
    rt0.close();

    st.close();
    cp.close();

    }
    catch(Exception e)
    {

    JOptionPane.showMessageDialog((Component)null,"SQL connection error","Error!!! ",JOptionPane.ERROR_MESSAGE);
    }
    tabbedPane.addTab("Subset Accuracy",p3);
    }
    class MenuItemHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent ev)
    {
    String s=ev.getActionCommand();
    if(s=="Exit")
    {
    System.exit(0);
    }
    else if(s=="Windows")
    {
    try
    {
    UIManager.setLookAndFeel(windowsLF);
    SwingUtilities.updateComponentTreeUI(decisionTree. this);
    }
    catch(Exception e)
    {
    System.out.println("Could not Load Windows Look n Feel");
    }
    }
    else if(s=="Motif")
    {
    try
    {
    UIManager.setLookAndFeel(motifLF);
    SwingUtilities.updateComponentTreeUI(decisionTree. this);
    }
    catch(Exception e)
    {
    System.out.println("Could not Load Motif Look n Feel");
    }
    }
    else if(s=="Metal")
    {
    try
    {
    UIManager.setLookAndFeel(metalLF);
    SwingUtilities.updateComponentTreeUI(decisionTree. this);
    }
    catch(Exception e)
    {
    System.out.println("Could not Load Metal Look n Feel");
    }
    }
    }
    }
    //----------------------------------------------------------- END__ MenuItemHandler ------
    //================================================== ========= START WindowEventHandler ===
    class WindowEventHandler extends WindowAdapter
    {
    public void windowClosing(WindowEvent e)
    {
    //close window on exit
    System.exit(0);
    }
    }
    }


    Plz help me!

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    286
    Rep Power
    10

    Default

    Same Statement reference for creating multiple ResultSets creates problem, thats what I found in your code. So use different Statement references for creating different resultsets.

    for e.g.
    Statement st=con.createStatement();
    ResultSet rst=st.executeQuery("select count(*) from table1");


    Statement st1=con.createStatement();
    ResultSet rst1=st.executeQuery("select count(*) from table2");

    It should solve your problem.

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    450
    Rep Power
    10

    Default

    My idea is ,open sql connection only when connection in closed.

    if you dont do,you may catch some sql exception
    Mak
    (Living @ Virtual World)

Similar Threads

  1. Hi Friends,
    By bihag in forum Introductions
    Replies: 3
    Last Post: 01-18-2009, 04:23 PM
  2. Hi friends
    By aditya in forum Introductions
    Replies: 1
    Last Post: 10-28-2008, 09:16 AM
  3. hello friends
    By amir_n in forum Introductions
    Replies: 1
    Last Post: 10-23-2008, 03:42 AM
  4. Hi Friends
    By pankajsharma in forum Introductions
    Replies: 0
    Last Post: 09-23-2008, 09:35 AM
  5. Hello Friends
    By vijaysdange in forum Introductions
    Replies: 3
    Last Post: 08-04-2008, 12:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •