标题:[急]Please help me,what's wrong?
取消只看楼主
ljz453780909
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-4-13
 问题点数:0 回复次数:3 
[急]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 
2007-12-04 15:42
ljz453780909
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-4-13
得分:0 
回复 1# 的帖子
运行结果就是:
不能实现查询功能,当查询一个学号时,就一直提示说:“抱歉,程序出现异常!”
我的意思就是这个程序可能那儿有点问题
自己找不出来
想实现查询功能

我没有对象,但我正在培养面向对象这种思维! QQ:453780909 邮箱:leijizhou@
2007-12-04 22:34
ljz453780909
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-4-13
得分:0 
回复 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
感觉就是没有一一对应,对应上了就对了!有人能帮我详细解释一下吗/?

我没有对象,但我正在培养面向对象这种思维! QQ:453780909 邮箱:leijizhou@
2007-12-06 08:36
ljz453780909
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-4-13
得分:0 
回复 7# 的帖子
原来如此!
多谢了
不过还有个问题
如果想有那个列的名字作为参数的话
怎么用
或者用那个函数啊?

[[italic] 本帖最后由 ljz453780909 于 2007-12-6 15:45 编辑 [/italic]]

我没有对象,但我正在培养面向对象这种思维! QQ:453780909 邮箱:leijizhou@
2007-12-06 15:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-190328-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.169864 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved