当前位置: 代码迷 >> Java相关 >> [急]Please help me,what's wrong?
  详细解决方案

[急]Please help me,what's wrong?

热度:526   发布时间:2007-12-04 15:42:02.0
[急]Please help me,what's wrong?
以一是我的一个实现查询,删除,修改功能的程序中的查询部分程序,其中ljz是我数据库中建的一个表,这个功能实现不了,操作是一直说"抱歉,程序出现异常!"帮忙看一那儿错了?      

//查找功能的实现
         if(e.getSource()==subMenu2[0]||e.getSource()==toolBarButton[0])
           {
              String idid = JOptionPane.showInputDialog("请输入要查找的学生学号");
              if(idid.trim()!="")
              {
                  String strSQL = "select * from ljz where id ='" + idid + "'";
                  try
                  {
                   //rs = st.executeQuery("select * from ljz where id ='2005162010'");
                      rs = st.executeQuery(strSQL);
                      int count = 0;
                      while(rs.next())
                       {
                             id = rs.getString("id");
                             name = rs.getString("name");
                             department = rs.getString("department");
                             sex = rs.getString("sex");
                             birthday = rs.getString("birthday");
                             nation = rs.getString("nation");
                             ++count;
                        }
                       if(count==0)
                             JOptionPane.showMessageDialog(null,"对不起,没有您要查找的学生!");
                       else
                       {
                             idT.setText(id);
                             nameT.setText(name);
                             sexT.setText(sex);
                             birthdayT.setText(birthday);
                             nationT.setText(nation);
                             departmentT.setText(department);
                        }
                    }
                    catch(Exception ex)
                    {
                         JOptionPane.showMessageDialog(null,"抱歉,程序出现异常!");
                    }
             }
        }

[[italic] 本帖最后由 ljz453780909 于 2007-12-4 16:02 编辑 [/italic]]
搜索更多相关的解决方案: wrong  Please  help  

----------------解决方案--------------------------------------------------------
错误内容粘出来
----------------解决方案--------------------------------------------------------
回复 1# 的帖子
运行结果就是:
不能实现查询功能,当查询一个学号时,就一直提示说:“抱歉,程序出现异常!”
我的意思就是这个程序可能那儿有点问题
自己找不出来
想实现查询功能
----------------解决方案--------------------------------------------------------
JOptionPane.showMessageDialog(null,"抱歉,程序出现异常!");

把异常打印出来
不要只提示个对话框
这样你怎么知道是哪里的问题呢 ???
----------------解决方案--------------------------------------------------------
对啊,毕竟人不是编译器啊,没有异常信息很难发现问题在哪儿的啊。e.printStackTrace();一下。
----------------解决方案--------------------------------------------------------
回复 4# 的帖子
问题找到了,是这样的.但我还是不明白原因:
               id = rs.getString("id");
                             name = rs.getString("name");
                             department = rs.getString("department");
                             sex = rs.getString("sex");
                             birthday = rs.getString("birthday");
                             nation = rs.getString("nation");
改成如下就对了:
            id = rs.getString(1);
                       name = rs.getString(2);
                       sex = rs.getString(3);
                       nation = rs.getString(4);
                       department = rs.getString(5);
                       birthday = rs.getString(6);
而我数据库(SQL2000)中的表是这样的:
哎,不能上传图片,只能打个表了
   id         name          sex           nation         department              birthday
  01          张三           男                汉                 05信管              1985-09-06
感觉就是没有一一对应,对应上了就对了!有人能帮我详细解释一下吗/?
----------------解决方案--------------------------------------------------------
ResultSet对象的getXXX()方法是以列序数为参数的,所以不能用列的名字作为参数
----------------解决方案--------------------------------------------------------
回复 7# 的帖子
原来如此!
多谢了
不过还有个问题
如果想有那个列的名字作为参数的话
怎么用
或者用那个函数啊?

[[italic] 本帖最后由 ljz453780909 于 2007-12-6 15:45 编辑 [/italic]]
----------------解决方案--------------------------------------------------------
  相关解决方案