
below describes a program of research that results in a table, my problem is that this same table to see it only accepts a single line even if I have more than one view as he only accepts a single line ... I am asking you to rewrite my program so you can scroll and data exists in more than one line ...
Thank you in advance for your answer.
package validation;
/** * * @author ACER */ 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 nome=t.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/lista", "root", "");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from listas where nome='"+nome+"'");
int id;
String apelido = "";
String pnome = " ";
String nomedomeio = "";
String telefone = "";
String email = "";
String endereco1 = " ";
String endereco2 = "";
String cidade = "";
String estado = " ";
String codigopostal = "";
String pais = "";
if(rs.next()){
id = rs.getInt("id");
apelido = rs.getString("apelido");
pnome = rs.getString("nome");
nomedomeio = rs.getString("nomedomeio");
telefone = rs.getString("telefone");
email = rs.getString("email");
endereco1 = rs.getString("endereco1");
endereco2 = rs.getString("endereco2");
cidade = rs.getString("cidade");
estado = rs.getString("estado");
codigopostal = rs.getString("codigopostal");
pais = rs.getString("pais");
}
String data[][]=new String[1][11];
data[0][0]=pnome;
data[0][1]=apelido;
data[0][2]=nomedomeio;
data[0][3]=telefone;
data[0][4]=email;
data[0][5]=endereco1;
data[0][6]=endereco2;
data[0][7]=cidade;
data[0][8]=estado;
data[0][9]=codigopostal;
data[0][10]=pais;
JFrame frame=new JFrame();
String labels[]={"Nome","Apelido","Nome do meio","Telefone","Email","Endereco1","Endereco2","Cidade","Estado","Codigo Postal","Pais"};
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);
}
}
});
}
}
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.