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:
Advertisements
display results on same jsp pagedisplay
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 pagedisplay
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 pagedisplay
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 panelmultiple 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 formDisplaying 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
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 dealsSame day travel deals Hi,
Can anyone compare
same day travel deals with different travel packages?
Thanks
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 pagepopulating 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
add same tables in jsp pageadd
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 looppython 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 timessame 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 rentalAgra
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
Hash value is not same - Java BeginnersHash 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 TourSame 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 textareaPosting 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 - StrutsSTRUTS-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
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 BeginnersPkg 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 computelocal 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
Show image and text on same jsp pageShow 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