永发信息网

java与数据库连接问题(关于空指针)

答案:1  悬赏:60  手机版
解决时间 2021-03-04 19:47
  • 提问者网友:精神病院里
  • 2021-03-03 19:34
package wh.one;

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 for(int j=0;j data[i][j]=rs.getString(j);

}

}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}

错误是Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
最佳答案
  • 五星知识达人网友:从此江山别
  • 2021-03-03 19:55
那样的错、dao代码呢
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯