Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
提示是playInfo[0][1]==null这错误publicvoidselect(){//显示某个查询的结果ii=scst.i;mscxh=scst.scxh;int...
提示是playInfo[0][1]==null这错误
public void select(){
//显示某个查询的结果
ii=scst.i;
mscxh=scst.scxh;
int j = 0;
playerInfo = new Object[ii][3];
String[] columnNames = {"学号","课程号","成绩"};
try{
rs = stmt.executeQuery("select * from sc where sno='"+mscxh+"'");
while(rs.next()){
playerInfo[j][0] =rs.getString("sno");
playerInfo[j][1] = rs.getString("cno");
playerInfo[j][2] = rs.getString("g");
j++;
}
}catch(SQLException e){
e.printStackTrace();
}
if(playerInfo[0][1]==null){
this.dispose();
JOptionPane.showMessageDialog(null, "课程号不存在!");
new SCM("选课信息管理").display();
}else{
sTable = new JTable(playerInfo,columnNames);
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
}
SCM中的方法是public void display(){
int i = 0;
int j = 0;
int k = 0;
List al = new ArrayList();
try{
rs = stmt.executeQuery("select* from sc");
while(rs.next()){
al.add(rs.getString("sno"));
al.add(rs.getString("cno"));
al.add(rs.getString("g"));
i++;
}
}catch(SQLException e){
e.printStackTrace();
}
playerInfo = new Object[i][3];
String[] columnNames={"学号","课程号","成绩"};
try{
rs = stmt.executeQuery("select* from sc order by sno");
while(rs.next()){
playerInfo[j][0]=rs.getString("sno");
playerInfo[j][1]=rs.getString("cno");
playerInfo[j][2]=rs.getString("g");
j++;
}
}catch(SQLException e){
e.printStackTrace();
}
sTable = new JTable(playerInfo,columnNames);//创建网格
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
} 展开
public void select(){
//显示某个查询的结果
ii=scst.i;
mscxh=scst.scxh;
int j = 0;
playerInfo = new Object[ii][3];
String[] columnNames = {"学号","课程号","成绩"};
try{
rs = stmt.executeQuery("select * from sc where sno='"+mscxh+"'");
while(rs.next()){
playerInfo[j][0] =rs.getString("sno");
playerInfo[j][1] = rs.getString("cno");
playerInfo[j][2] = rs.getString("g");
j++;
}
}catch(SQLException e){
e.printStackTrace();
}
if(playerInfo[0][1]==null){
this.dispose();
JOptionPane.showMessageDialog(null, "课程号不存在!");
new SCM("选课信息管理").display();
}else{
sTable = new JTable(playerInfo,columnNames);
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
}
SCM中的方法是public void display(){
int i = 0;
int j = 0;
int k = 0;
List al = new ArrayList();
try{
rs = stmt.executeQuery("select* from sc");
while(rs.next()){
al.add(rs.getString("sno"));
al.add(rs.getString("cno"));
al.add(rs.getString("g"));
i++;
}
}catch(SQLException e){
e.printStackTrace();
}
playerInfo = new Object[i][3];
String[] columnNames={"学号","课程号","成绩"};
try{
rs = stmt.executeQuery("select* from sc order by sno");
while(rs.next()){
playerInfo[j][0]=rs.getString("sno");
playerInfo[j][1]=rs.getString("cno");
playerInfo[j][2]=rs.getString("g");
j++;
}
}catch(SQLException e){
e.printStackTrace();
}
sTable = new JTable(playerInfo,columnNames);//创建网格
p1.add(sTable);
scroll = new JScrollPane(sTable);
this.add(scroll);
} 展开
1个回答
展开全部
应该是一条记录都没有。所以,还要作判断。
还有, playerInfo = new Object[ii][3]; 中的ii
还有, playerInfo = new Object[ii][3]; 中的ii
追问
可以再说的详细一点吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
帕剌斯
2024-10-29 广告
2024-10-29 广告
德国Palas 成立于1983年,总部位于德国巴登符腾堡州的卡尔斯鲁厄。作为气溶胶技术专家, Palas 致力于为用户提供气溶胶颗粒物的产生、处理、测量与分析解决方案,是该领域内全球先进的开发商和制造商。基于自身技术的独特优势,Palas ...
点击进入详情页
本回答由帕剌斯提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询