
Hello Sir,
Sir i do have one more query ,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 search field and button is present .
please Sir, send me the code for that. will always be gratefull. Thanking you nd waiting for reply ........

Here is a code that search the data from the database and show multiple identical rows from database on clicking search button to jtable.
import java.awt.*;
import java.sql.*;
import java.util.*;
import java.awt.event.*;
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();
f.setLayout(null);
lab.setBounds(10,10,100,20);
t.setBounds(120,10,100,20);
b.setBounds(120,40,80,20);
pane.setBounds(10,70,480,170);
pane.setVisible(false);
f.add(lab);
f.add(t);
f.add(b);
f.add(pane);
pane.setVisible(false);
f.setSize(500,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/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from data 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);
}
DefaultTableModel model=new DefaultTableModel(data, columnNames);
table.setModel(model);
pane.setVisible(true);
}
catch(Exception ex){
System.out.println(e);
}
}
});
}
}

Thank you deepak Thank you very much .Excellent job .
once again thanx ...........
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.