Displaying search results in same panel of gridview in same jframe window.

Displaying search results in same panel of gridview in same jframe window.

Hello Sir, I have a search frame window from which we can search and see the results in the same panel of the Jframe in Gridview Jtable format ...

Jtable is being constructed dynamically based on columns of database query....

But when we execute search for the second time database table columns are also being added alongwith the search result fields in the dynamically created Jtable Gridview ....

Sir, According to my requirement i need results in the Jtable gridview format in the sam epanel of jframe window .But when i execute second search first search result should be deleted and current search result should be displayed in the jpanel of jframe window....

import java.sql.*; import java.util.*; import java.awt.event.*; import java.lang.String; import javax.swing.*; import javax.swing.table.*;

class search{ public static void main(String[] args) { final Vector columnNames = new Vector(); final Vector data = new Vector();

    JLabel lab=new JLabel("Enter Name:");
    final JTextField t=new JTextField(20);
    JButton b = new JButton("Search");
    final JTable table=new JTable();
    final JScrollPane pane=new JScrollPane(table);

    JFrame f = new JFrame();

    lab.setBounds(10,10,100,20);
    t.setBounds(120,10,100,20);
    b.setBounds(120,40,80,20);
   pane.setBounds(10,90,480,170);
 f.add(lab);
    f.add(t);
    f.add(b);
    f.add(pane);
   f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
   pane.setVisible(false);
    f.setSize(600,300);
    f.setVisible(true);


    b.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent e){

      String name=t.getText();

        try{
       Class.forName("com.mysql.jdbc.Driver");
       Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/techsoft", "root", "techsoft");
       Statement st=con.createStatement();
       ResultSet rs=st.executeQuery("select * from ankur where name='"+name+"'");
       ResultSetMetaData md = rs.getMetaData();
       int columns = md.getColumnCount();
        for (int i = 1; i <= columns; i++){
        columnNames.addElement(md.getColumnName(i) );
        }
        while(rs.next()){
        Vector row = new Vector(columns);
        for (int i= 1; i <= columns; i++){
        row.addElement( rs.getObject(i) );
        }
        data.addElement(row);



        Vector str=columnNames;

         DefaultTableModel model=new DefaultTableModel(data,str);
         table.setModel(model);

         pane.setVisible(true);
        }
        }

        catch(Exception ex){
        System.out.println(e);
        }
      }
    });



}

}

View Answers









Related Tutorials/Questions & Answers:
Displaying search results in same panel of gridview in same jframe window.
Displaying search results in same panel of gridview in same jframe window... search and see the results in the same panel of the Jframe in Gridview Jtable... in the Jtable gridview format in the sam epanel of jframe window .But when i execute
Displaying search results in same panel of gridview in same jframe window.
Displaying search results in same panel of gridview in same jframe window... search and see the results in the same panel of the Jframe in Gridview Jtable... in the Jtable gridview format in the sam epanel of jframe window .But when i execute
Advertisements
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... ,In the given code search results is being displayed in the other jframe. But in my application i need to show search results in the same panel of jframe to where
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... where i have to show the search result in the same panel of where search field... only current search results alongwith the column as header of gridview
How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...
the textfields and submit button in the same panel of the jframe window . Below is my code which is displaying textfields in the other jframe. KIndly help me sir...How to open textfields in the the same panel of the jframe by selcting from
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
multiple records on same panel
multiple records on same panel  i have multiple access of records and i want to display all of them at one panel.Each time a new panel opens for a keyrecord , i want just to show records on same panel or frame, whatever u can
Displaying error on the Same form
Displaying error on the Same form  I want to display the errors on the same form(Top of the form) after validation. I am used Div element and Table.... There is a root Div element they are using for Window purpose. I tried to resize it using DOM
jtable displays search results
jtable displays search results   hi sir can u send me full source code for displaying search results into jtable from database n jtable n search button must be within same frame but in different Panel and the size of the frame
Displaying the same image in a JPanel and using scroll - HELP - Java Beginners
Displaying the same image in a JPanel and using scroll - HELP  I hope... JFrame implements ActionListener { private Dimension area; //indicates area...){} private static void createAndShowGUI() { //Create and set up the window
displaying data based on criteria from 2 tables having same type of data - Java Beginners
displaying data based on criteria from 2 tables having same type of data ... to process search criteria without having a form. I have recently read up about...) to process a search. The search will have following features:- 1
get data in pop up window droplists and on selecting data in the same show a grid table with related datas
get data in pop up window droplists and on selecting data in the same show... a pop up window appears with two drop down lists and a button. One of the drop... on the button I need to get the list of hotels in a table grid format on the same
Displaying Error pages in results tree in jmeter
Displaying Error pages in results tree in jmeter   Displaying Error pages in results tree in jmeter
ModuleNotFoundError: No module named 'same'
ModuleNotFoundError: No module named 'same'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'same' How to remove the ModuleNotFoundError: No module named 'same' error
ModuleNotFoundError: No module named 'same'
ModuleNotFoundError: No module named 'same'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'same' How to remove the ModuleNotFoundError: No module named 'same' error
Same day travel deals
Same day travel deals  Hi, Can anyone compare same day travel deals with different travel packages? Thanks
Displaying checked checkbox in same page as well as print on another page ....also add next pages cheches checkbox into previous list
Displaying checked checkbox in same page as well as print on another page... it contains same checkboxes.ADS_TO_REPLACE_2 So, from your above code, i can display selected checkbox on same page. It works... But when i go to another
Servlets errors in same page.
Servlets errors in same page.  How do I display errors list in the same page where a form field exists using servlets...........i.e. without using JSP? Please explain with a simple username password program
Are J2EE and Java Advanced the same?
Are J2EE and Java Advanced the same?  Hi, I am checking J2EE and Advanced Java. Are J2EE and Java Advanced the same? Thanks   Hi, J2EE is now renamed to JEE in latest version of Java platform, which is Specification
Is data science and analytics same?
Is data science and analytics same?  Hi, I am beginner in Data...: Is data science and analytics same? Try to provide me good examples or tutorials links so that I can learn the topic "Is data science and analytics same
Is AI same as ML?
Is AI same as ML?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Is AI same as ML... "Is AI same as ML?". Also tell me which is the good training courses
populating a screen on the same page
populating a screen on the same page  i'm making a time table in jsp. i have put button on each slot.if a person click on that slot it'll redirect to a new page which will help them to choose the subject and faculty through drop
Two or more actions in the same form
Two or more actions in the same form  Can I have two or more actions in the same form
more Submit buttons in the same form
more Submit buttons in the same form  Can I have two or more Submit buttons in the same form
login for different user in the same page
login for different user in the same page  how can i do the login for different user in the same page throug jsp
add same tables in jsp page
add same tables in jsp page  hi I have a table in my jsp page with data, now I want to add same copy of table without its default value in same page whenever I click add more table, how do I do
python print on same line in loop
python print on same line in loop  Hi, I have a unique requirement in Python where I have to print data in the same line. When I am using... this and print in the same line. Let's know how to make function in Python to print data
same data inserted 2 times
same data inserted 2 times  thanks for reply, i know the insert command. but same data inserted 2 times.where is the problem i cannot understood
Agra same day car rental
Agra same day car rental  Hi, I want to see the Taj Mahal but just wondering where to book car on rental for the same day trip to Taj Mahal? Thanks
Retrieve all the students in the same year(Java ArrayList)?
in the same year search = null; search...Retrieve all the students in the same year(Java ArrayList)?  FoundStudents.jsp year- parameter I receive from a form search- is an object of type
Hash value is not same - Java Beginners
Hash value is not same  Hi, I've two Excel files with same data. One is in Excel 2003 (.xls) format and other one is in Excel 2007 (.xlsx) format... 2003 files is not same as the hash value of Excel 2007 file. What might
Same Day Agra Tour
Same Day Agra Tour We are offering Same Day Agra Tour that enables you to see the various tourists attractions in Agra in a single day. The Same Day Agra... for Same Day Agra Tour 0500 Hrs: Pick up from Delhi Hotel 0830 Hrs: Arrival
DOJO+Creating button of same size.
DOJO+Creating button of same size.  I am trying to create two buttons in DOJO of equal size. But the size of the buttons varies depending upon the name of the button that will get displayed. I tried by giving a class atribute
Posting comments to same page with textarea
Posting comments to same page with textarea  I have been given some code which allows a user to type a comment and on submit it will return the text to the same page. Many thanks for that. However I wanted it to add other
STRUTS-display search results - Struts
STRUTS-display search results  Hii, I am a beginner in struts..I want to retrieve few records from database and display in jsp page.First i tried... them in jsp.. Search Results
Is big data and data science same?
Is big data and data science same?  Hi, I am beginner in Data...: Is big data and data science same? Try to provide me good examples or tutorials links so that I can learn the topic "Is big data and data science same?"
Is Data Analyst same as data scientist?
Is Data Analyst same as data scientist?  Hi, I am beginner in Data...: Is Data Analyst same as data scientist? Try to provide me good examples or tutorials links so that I can learn the topic "Is Data Analyst same as data
Avoiding all the messages shown on the same line
Avoiding all the messages shown on the same line  How to avoid that all the messages are shown on the same line
Using insert update and delete in the same servlet
Using insert update and delete in the same servlet  How to write insert, update and delete coding in the same servlet
to upload a table from DB to the same html page
to upload a table from DB to the same html page  how to make this booklist table to be opened in the same html page itself using a third frame
same thing i want but from db..
same thing i want but from db..  http://www.roseindia.net/tutorial/javascript/dynamicCombo.html same thing i want but from db
Pkg Inheritance under same pkg - Java Beginners
Pkg Inheritance under same pkg   Hi Friends I want to extend the Predefined ( . java File ) class in a another inherited class( .java file ) in the same pkg If this is allowed in the same pkg, please tell me how
local host sharing on same network compute
local host sharing on same network compute  i have an desktop bill application on wamp and i want to use it on other computer on same network . computer connected with hub or switch
ModuleNotFoundError: No module named 'google-search-results'
ModuleNotFoundError: No module named 'google-search-results'  Hi...: No module named 'google-search-results' How to remove the ModuleNotFoundError: No module named 'google-search-results' error? Thanks   Hi
ModuleNotFoundError: No module named 'google-search-results'
ModuleNotFoundError: No module named 'google-search-results'  Hi...: No module named 'google-search-results' How to remove the ModuleNotFoundError: No module named 'google-search-results' error? Thanks   Hi
ModuleNotFoundError: No module named 'google-search-results-serpwow'
ModuleNotFoundError: No module named 'google-search-results-serpwow'  ...: No module named 'google-search-results-serpwow' How to remove the ModuleNotFoundError: No module named 'google-search-results-serpwow' error
Get form value in same page - JSP-Servlet
Get form value in same page  Hello friends, Can we get a form field value in the same to be processed in java coding. For example
Show image and text on same jsp page
Show image and text on same jsp page  Hi all, I have to display image and text on the same jsp page. The text and image are both retrived from mysql database. The image is shown correctly on seperate jsp page but when shown

Ads