
I first im not speak englis very well, so my question is:
how can i make search data in JTable of java?
i wan to search records in table or textfield but the data display in JTable.
Note: i dont have a table.
PLEASE HELP.... THANKS

import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
class Search{
public static void main(String[] args) {
JLabel lab=new JLabel("Enter Name:");
final JTextField t=new JTextField(20);
JButton b = new JButton("Search");
JPanel p = new JPanel(new GridLayout(2,2));
p.add(lab);
p.add(t);
p.add(b);
JFrame f = new JFrame();
f.getContentPane().add(p);
f.pack();
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+"'");
String n="",add="",contact="",email="";
if(rs.next()){
n=rs.getString("name");
add=rs.getString("address");
contact=rs.getString("contactNo");
email=rs.getString("email");
}
String data[][]=new String[1][4];
data[0][0]=n;
data[0][1]=add;
data[0][2]=contact;
data[0][3]=email;
JFrame frame=new JFrame();
String labels[]={"Name","Address","Contact No","Email"};
JTable table=new JTable(data,labels);
JScrollPane pane=new JScrollPane(table);
frame.add(pane);
frame.setVisible(true);
frame.pack();
}
catch(Exception ex){
System.out.println(e);
}
}
});
}
}

thanks for you answer, now I can see by the code in my project ...

Thanks I managed to enter the code in my project so give me this error when I call my button, for example in another package a class called desktopapplication i have an interface that runs on my table this in mysql, so I do not interface desktopapplication I have a button called search, but the button is called I put the code:
search demo = new search (); demo.actionPerformed (evt);
but he did not recognize that the action perfomed. because it will be???
tou asking for your help once again .................
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.