class InsertRecord extends JDialog implements ActionListener{ //负责插入记录的类
JLabel hintLabel;
Object[] name={"学号","姓名","性别","年龄"};
Object[][] a=new Object[1][4];
JTable table;
JButton enterInsert;
Connection con;
Statement sql;
ResultSet rs;
String num;
InsertRecord(String s){
setTitle(s);
hintLabel=new JLabel("输入新记录:");
table=new JTable(a,name);
enterInsert=new JButton("插入新记录");
setLayout(null);
Box baseBox=Box.createHorizontalBox();
baseBox.add(hintLabel);
baseBox.add(new JScrollPane(table));
baseBox.add(enterInsert);
add(baseBox);
baseBox.setBounds(10,40,600,38);
enterInsert.addActionListener(this);
setBounds(120,160,700,200);
}
public void actionPerformed(ActionEvent e){
/* try{ con=DriverManager.getConnection("jdbc:odbc:jec","system","jec");
sql=con.createStatement();
int k=sql.executeUpdate
("INSERT INTO s VALUES('a[0][0]','a[0][1]','a[0][2]','a[0][3]')");
if(k==1)
JOptionPane.showMessageDialog
(this,"插入记录成功","成功",JOptionPane.PLAIN_MESSAGE);
table=new JTable(a,name);
con.close();
}
catch(SQLException ee){
JOptionPane.showMessageDialog
(this,"插入记录失败"+ee,"失败",JOptionPane.ERROR_MESSAGE);
} */
System.out.println(a[0][0]+""+a[0][1]+""+a[0][2]+""+a[0][3]);
}
}
为什么a[0][3]显示为null 其他的都显示正常 谁能帮我解决一下
JLabel hintLabel;
Object[] name={"学号","姓名","性别","年龄"};
Object[][] a=new Object[1][4];
JTable table;
JButton enterInsert;
Connection con;
Statement sql;
ResultSet rs;
String num;
InsertRecord(String s){
setTitle(s);
hintLabel=new JLabel("输入新记录:");
table=new JTable(a,name);
enterInsert=new JButton("插入新记录");
setLayout(null);
Box baseBox=Box.createHorizontalBox();
baseBox.add(hintLabel);
baseBox.add(new JScrollPane(table));
baseBox.add(enterInsert);
add(baseBox);
baseBox.setBounds(10,40,600,38);
enterInsert.addActionListener(this);
setBounds(120,160,700,200);
}
public void actionPerformed(ActionEvent e){
/* try{ con=DriverManager.getConnection("jdbc:odbc:jec","system","jec");
sql=con.createStatement();
int k=sql.executeUpdate
("INSERT INTO s VALUES('a[0][0]','a[0][1]','a[0][2]','a[0][3]')");
if(k==1)
JOptionPane.showMessageDialog
(this,"插入记录成功","成功",JOptionPane.PLAIN_MESSAGE);
table=new JTable(a,name);
con.close();
}
catch(SQLException ee){
JOptionPane.showMessageDialog
(this,"插入记录失败"+ee,"失败",JOptionPane.ERROR_MESSAGE);
} */
System.out.println(a[0][0]+""+a[0][1]+""+a[0][2]+""+a[0][3]);
}
}
为什么a[0][3]显示为null 其他的都显示正常 谁能帮我解决一下
只有3个 你再加一个就可以了吧 数组的下标是从0开始的