import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
public class GUIFrameData extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
String[] colnames={"ID","Name","Age","Dept"};
JTextField fx;
String[][] data={};
public void showDBData(){
JTable jt=new JTable(data,colnames);
JScrollPane scrollpane=new JScrollPane(jt);
JPanel jp=new JPanel();
JTextField fx=new JTextField(20);
JButton jb=new JButton("search");
jp.add(fx);
jp.add(jb);
this.add(scrollpane,BorderLayout.CENTER);
this.add(jp,BorderLayout.NORTH);
jb.addActionListener(this);
this.setVisible(true);
this.setLocation(260,150);
this.setSize(500,260);
this.validate();
this.setDefaultCloseOperation(3);
}
public void actionPerformed(ActionEvent e) {
String input=fx.getText();
DBOperation dbo=new DBOperation();
ResultSet rs=dbo.getDataFromStu(input);
try {
rs.last();
int rowcount=0;
int colcount=0;
data=new String[rowcount][colcount];
rowcount=rs.getRow();
colcount=rs.getMetaData().getColumnCount();
rs.first();
for(int i=0;i
}
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
错误是Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException