JAVA查询人员信息问题
//查询人员信息界面import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.event.*;
///////////////////////////////////// 人员信息查询 /////////////////////////////////////////
/**
* 树第一节点下的第四叶子
* 人员信息查询管理
*/
public class Node13 extends JPanel implements ActionListener{
//定义所用的面板
JPanel upPanel = new JPanel();
JPanel centerPanel = new JPanel();
JPanel downPanel = new JPanel();
//定义图形界面元素
JLabel jLabel = new JLabel();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
//定义表格
JScrollPane jScrollPane1;
JTable jTable;
ListSelectionModel listSelectionModel = null;
String[] colName = {"编号","名字"/*,"月基本工资","生产部件总价值","月平均奖金","车间","个人月奖金","生产部件型号"*/};
String[][] colValue;
GridBagLayout girdBag = new GridBagLayout();
GridBagConstraints girdBagCon;
public Node13() {
this.setLayout(new BorderLayout());
try {
upInit(); //上部面板布局
centerInit(); //中部面板布局
downInit(); //下部面板布局
addListener();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**
* 上部面板的布局
*/
public void upInit() throws Exception {
Operation oper = new Operation();
upPanel.setLayout(girdBag);
try {
jLabel.setText("人员信息查询");
jLabel.setFont(new Font("Dialog",0,16));
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 0;
girdBagCon.gridy = 0;
girdBagCon.insets = new Insets(0,10,0,10);
girdBag.setConstraints(jLabel,girdBagCon);
centerPanel.add(jLabel);
upPanel.add(jLabel);
colValue = oper.searchAll();
jTable = new JTable(colValue,colName);
jTable.setPreferredScrollableViewportSize(new Dimension(450,380));
jScrollPane1 = new JScrollPane(jTable);
jScrollPane1.setPreferredSize(new Dimension(450,380));
girdBagCon = new GridBagConstraints();
girdBagCon.gridx = 0;
girdBagCon.gridy = 1;
girdBagCon.insets = new Insets(0,0,0,0);
girdBag.setConstraints(jScrollPane1,girdBagCon);
upPanel.add(jScrollPane1);
}
catch(Exception e) {
e.printStackTrace();
}
//添加上部面板
this.add(upPanel,BorderLayout.NORTH);
}
/**
* 中部面板的布局
*/
public void centerInit() throws Exception {
}
/**
* 下部面板的布局
*/
public void downInit(){
}
/**
* 添加事件侦听
*/
public void addListener() throws Exception {
}
/**
* 事件处理
*/
public void actionPerformed(ActionEvent e) {
}
}
//各类操作的代码
import java.sql.ResultSet;
import javax.swing.JOptionPane;
public class Operation {
String loaction1;
String loaction2;
String loaction3;
String loaction4;
String loaction5;
String loaction6;
String loaction7;
String loaction8;
String sql;
ResultSet rs=null;
//增加人员信息
public void add(String l1,String l2,String l3,String l4,
String l5,String l6,String l7,String l8){
sqlconnection sqlc = new sqlconnection();
this.loaction1=l1;
this.loaction2=l2;
this.loaction3=l3;
this.loaction4=l4;
this.loaction5=l5;
this.loaction6=l6;
this.loaction7=l7;
this.loaction8=l8;
sql="insert into worker(wno,wname,bsalary,uprize,avprize,workshop,pavprize,conponentno) "
+"values ('"+loaction1+"','"+loaction2+"','"+loaction3+"','"+loaction4+"'," +
"'"+loaction5+"','"+loaction6+"'," +"'"+loaction7+"','"+loaction8+"')";
try {
sqlc.OpenConn();
sqlc.executeUpdate(sql);
//JOptionPane.showMessageDialog(null,"成功添加一条新的纪录!");
} catch (Exception e) {
e.printStackTrace();
}
finally{
sqlc.closeStmt();
sqlc.closeConn();
}
}
public void delete(String l1){
sqlconnection sqlc = new sqlconnection();
this.loaction1=l1;
sql = "delete from worker where wno= "+loaction1+"";
try {
sqlc.OpenConn();
sqlc.executeUpdate(sql);
//JOptionPane.showMessageDialog(null,"成功删除一条新的纪录!");
} catch (Exception e) {
e.printStackTrace();
}
finally{
sqlc.closeStmt();
sqlc.closeConn();
}
}
//删除人员信息
public void modify(String l1, String l2, String l3){
sqlconnection sqlc = new sqlconnection();
this.loaction1 = l1;
this.loaction2 = l2;
this.loaction3 = l3;
sql = "update worker set wname = '"+loaction1+"', bsalary = '"+loaction3+"' where wno = "+loaction1+"";
try{
sqlc.OpenConn();
sqlc.executeUpdate(sql);
//JOptionPane.showMessageDialog(null,"成功修改一条新的纪录!");
}
catch(Exception e){
System.out.println(e);
//JOptionPane.showMessageDialog(null, "更新失败", "错误", JOptionPane.ERROR_MESSAGE);
}
finally {
sqlc.closeStmt();
sqlc.closeConn();
}
}
//删除信息面板所需的所有信息函数
public String[][] searchAll(){
sqlconnection sqlc = new sqlconnection();
String[][] sn = null;
int row = 0;
int i = 0;
sql = "select * from worker order by wno";
try{
sqlc.OpenConn();
rs = sqlc.executeQuery(sql);
if(rs.last()){
row = rs.getRow();
}
if(row == 0){
sn = new String[1][2];
sn[0][0] = " ";
sn[0][1] = " ";
/*sn[0][2] = " ";
sn[0][3] = " ";
sn[0][4] = " ";
sn[0][5] = " ";
sn[0][6] = " ";
sn[0][7] = " ";*/
}
else{
sn = new String[row][2];
rs.first();
rs.previous();
while(rs.next()){
sn[i][0] = rs.getString(1);
sn[i][1] = rs.getString(2);
/*sn[i][2] = rs.getString(3);
sn[i][3] = rs.getString(4);
sn[i][4] = rs.getString(5);
sn[i][5] = rs.getString(6);
sn[i][6] = rs.getString(7);
sn[i][7] = rs.getString(8);*/
i++;
}//wno,wname,bsalary,uprize,avprize,workshop,pavprize,conponentno
}
}
catch(Exception e){
}
finally {
sqlc.closeStmt();
sqlc.closeConn();
}
return sn;
}
/**
* 获得表中的所有编号
*/
public String[] getAllId(){
String[] s = null;
int row = 0;
int i = 0;
sqlconnection sqlc = new sqlconnection();
sql = "select wno from worker order by wno";
try{
sqlc.OpenConn();
rs = sqlc.executeQuery(sql);
if(rs.last()){
row = rs.getRow();
}
if(row == 0){
s = null;
}
else{
s = new String[row];
rs.first();
rs.previous();
while(rs.next()){
s[i] = rs.getString(1);
i++;
}
}
}
catch(Exception e){
System.out.println(e);
}
finally {
sqlc.closeStmt();
sqlc.closeConn();
}
return s;
}
/**
* 根据编号查询信息
*/
public String[] search(String l1){
sqlconnection sqlc = new sqlconnection();
this.loaction1 = l1;
String[] s = new String[7];
sql = "select * from worker where wno = "+loaction1+"";
try{
sqlc.OpenConn();
rs = sqlc.executeQuery(sql);
if(rs.next()){
s[0] = rs.getString("wno");
s[1] = rs.getString("wno");
s[2] = rs.getString("wno");
}
else
s = null;
}
catch(Exception e){
}
finally {
sqlc.closeStmt();
sqlc.closeConn();
}
return s;
}
/*
*转换编码
*/
public static String toGBK(String str){
try {
if(str==null)
str = "";
else
str=new String(str.getBytes("ISO-8859-1"),"GBK");
}
catch (Exception e) {System.out.println(e);}
return str;
}
}
在查询人员信息界面中,colValue = oper.searchAll();这个函数中出现了问题,查询不了出现异常
dnode=查看员工信息
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.JTable$1.getRowCount(JTable.java:665)
at javax.swing.JTable.getRowCount(JTable.java:2640)
at javax.swing.plaf.basic.BasicTableUI.createTableSize(BasicTableUI.java:1649)
at javax.swing.plaf.basic.BasicTableUI.getPreferredSize(BasicTableUI.java:1690)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1632)
at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:769)
at java.awt.Container.layout(Container.java:1421)
at java.awt.Container.doLayout(Container.java:1410)
at java.awt.Container.validateTree(Container.java:1507)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validate(Container.java:1480)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:670)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:127)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
在线等,求大神解救哇!!
补充:Java , Java SE