[nbusers] Need help to correct search engine java netbeans code

  • From: "Silent_Heart" < >
  • To:
  • Subject: [nbusers] Need help to correct search engine java netbeans code
  • Date: Fri, 23 Nov 2012 04:08:11 -0500

Hello every one

i am creating advance search engine for my final year project in Java using 
netbeans IDE and the advance search engine is working start but i have two 
main problem that are explain below:

1. First Problem: 
when i put "Admission No 1" then hit Search button. the record is not visible 
until i press mouse click on Jtable Columns name area after that the record 
is displaying and the records are not directly displaying without mouse click.

2. Second Problem: 
when i put another "Admission No 2" then hit Search button but the record 
still old one is displaying on the JTable and not displaying new one record 
on the JTable.

check for snapshot below link:

1. http://i47.tinypic.com/8yzzut.jpg

2. http://i47.tinypic.com/33xkls4.jpg

plz any body correct and solve those two problems in my code 

 my search engine source code:

   

Code:

 package abc;
    
    import java.awt.HeadlessException;
    import java.sql.*;
    import javax.swing.*;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author Silent Heart
     */
    public class tst extends javax.swing.JFrame {
         
        int flag=0,rows=0,a=0,b=0;
        String cid;
        Object data[][];
        JTable table;
        JScrollPane jsp;
        ResultSet res;
        ResultSet rst;
     
        Connection conn=null; 
    
        /** Creates new form tst */
        public tst() {
            initComponents();
            conn=Conect.Connector();
            
            setVisible(true);
            setSize(800,600);
            setTitle("Search Student");
            ButtonGroup bg=new ButtonGroup();
            bg.add(jRadioButton1);
            bg.add(jRadioButton2);
    
        }
        
         public void tabledisp()
        {
            try
                    {
    
                        data=new Object[rows][15];
                        Object[] colheads={" Student Id"," Name"," Father 
Name"," City","Date"};
                        
                        Statement stmt=conn.createStatement();
    
                        rst=stmt.executeQuery("select * from srh");
                        for(int i=0;i<rows;i++)
                        {
                                rst.next();
                                for(int j=0;j<5;j++)
                                {
                                    data [i][j]=rst.getString(j+1);
                                    System.out.println(data[i][j]);
                                }
                        }
                        table=new JTable(data,colheads);
    
                        int 
v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
                        int 
h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
                        jsp=new JScrollPane(table,v,h);
                        jsp.setBounds(10,180,680,300);
                        jPanel1.add(jsp);
                        add(jsp);
                        System.out.println("we came here");
                        rows=0;
    
                    }
                    catch(Exception e)
                    {
                        JOptionPane.showMessageDialog(null,"here the error 
is:"+e);
                    }
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")

        Generated code                       
    
        private void btnActionPerformed(java.awt.event.ActionEvent evt) {     
                               
    
            if(jTextField1.getText().equals(""))
            {
                jLabel3.setText("Entry Is Must");
                jTextField1.setText("");
            }
            else
            {
                jLabel3.setText("");
                cid=jTextField1.getText();
                if(flag==0)
                {
                    try
                    {
                        Statement st=conn.createStatement();
                        st.executeUpdate("delete srh");
                        res=st.executeQuery("select * from info");
                        Boolean rec=res.next();
                        if(rec==false)
                        {
                            JOptionPane.showMessageDialog(null,"There are no 
customers exists");
                            jTextField1.setText("");
                        }
                        else
                        {
                            do
                            {
                                String sid=res.getString(1);
                                String sname=res.getString(2);
                                String sfname=res.getString(3);
                                String scity=res.getString(4);
                                String sdate=res.getString(5);
    
    
                                if(cid.equalsIgnoreCase(sid))
                                {
                                    PreparedStatement 
prp=conn.prepareStatement("insert into srh values(?,?,?,?,?)");
                                    prp.setString(1,sid);
                                    prp.setString(2,sname);
                                    prp.setString(3,sfname);
                                    prp.setString(4,scity);
                                    prp.setString(5,sdate);
    
                                    prp.executeUpdate();
                                    rows++;
                                    System.out.println(rows);
                                    System.out.println("i came here");
    
                                    a=1;
    
                                    jTextField1.setText("");
    
                                }
                                
                            }while(res.next());
                            if(a==0)
                            {
                                JOptionPane.showMessageDialog(null,"The 
customer ID does not exists");
                                jTextField1.setText("");
                            }
                        }

                    }
                    catch(Exception e)
                    {
                        JOptionPane.showMessageDialog(null,"The error is:"+e);
                    }
                    tabledisp();
                }
                if(flag==1)
                {
                    try
                    {
    
                        Statement st=conn.createStatement();
                        st.executeUpdate("delete srh");
                        res=st.executeQuery("select * from info");
                        Boolean rec=res.next();
                        if(rec==false)
                        {
                            JOptionPane.showMessageDialog(null,"There are no 
customers exists");
                            jTextField1.setText("");
                        }
                        else
                        {
                            do
                            {
                                 String sid=res.getString(1);
                                String sname=res.getString(2);
                                String sfname=res.getString(3);
                                String scity=res.getString(4);
                                String sdate=res.getString(5);
    
                                if(cid.equals(sname))
                                {
                                    PreparedStatement 
prp=conn.prepareStatement("insert into srh values(?,?,?,?,?)");
                                    prp.setString(1,sid);
                                    prp.setString(2,sname);
                                    prp.setString(3,sfname);
                                    prp.setString(4,scity);
                                    prp.setString(5,sdate);
    
                                    prp.executeUpdate();
                                    rows++;
                                    System.out.println(rows);
                                    System.out.println("i came here");
    
                                    b=1;
    
                                    jTextField1.setText("");
    
                                }
                                
                            }while(res.next());
                            if(b==0)
                            {
                                JOptionPane.showMessageDialog(null,"The 
customer Name does not exists");
                                jTextField1.setText("");
                            }
                        }

                    }
                    catch(SQLException | HeadlessException e)
                    {
                        JOptionPane.showMessageDialog(null,"The error is:"+e);
                    }
                    tabledisp();
                }
            }
    
        }                                                                     
    
    
        private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent 
evt) {                                              

            flag=0;
        }                                             
    
        private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent 
evt) {                                              
            flag=1;
        }                                             
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /* Set the Nimbus look and feel */
            
             Look and feel setting code (optional)
    
            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new tst().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify                     
        private javax.swing.JButton btn;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JRadioButton jRadioButton1;
        private javax.swing.JRadioButton jRadioButton2;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                   
    }




Thanks

Ayaz Ali






[nbusers] Need help to correct search engine java netbeans code

Silent_Heart 11/23/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close