读书人

经常做日本项目的朋友请求帮忙!解决

发布时间: 2012-01-05 22:36:54 作者: rapoo

经常做日本项目的朋友,请求帮忙!!

当我点"下一条"按钮,直到点到最后一条,出现了上图出现的错误的错误,不直到什么意思,看看我的代码

Java code
    private static ResultSet rs=null;    private static Statement aStatement=null;    private static Connection aConnection=null;private static void getDBConnection()    {        try        {            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");            aConnection=DriverManager.getConnection("jdbc:odbc:mydata","sa","sa");        }catch(ClassNotFoundException e1)        {            JOptionPane.showMessageDialog(null, "驱动没找到,连接失败","Error",JOptionPane.ERROR_MESSAGE);                    }catch(SQLException e2)        {            JOptionPane.showMessageDialog(null, "用户名密码错误,连接失败","Error",JOptionPane.ERROR_MESSAGE);                    }    }public static Vector getAll()    {        Vector <Category> Categories=new Vector();        String strSQL;        strSQL="SELECT * FROM Categories";        try        {            getDBConnection();            aStatement=aConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);            rs=aStatement.executeQuery(strSQL);            while (rs.next())            {                Category aCategory=new Category();                aCategory.setCategoryID(rs.getInt("CategoryID"));                aCategory.setCategoryName(rs.getString("CategoryName"));                aCategory.setDescription(rs.getString("Description"));                byte [] buf1=rs.getBytes("Picture");                aCategory.setPicture(buf1);                                Categories.add(aCategory);            }            rs.first();        }        catch(SQLException e)        {            JOptionPane.showMessageDialog(null, e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);                    }        return Categories;    }public static Category GetNextCategory()    {        Category aCategory=new Category();        try        {            if (rs.isLast())            {                JOptionPane.showMessageDialog(null, "已经是最后一条记录了","提示",JOptionPane.INFORMATION_MESSAGE);            }            else            {                rs.next();                            }            aCategory=getCategory(rs);        }catch(SQLException e)        {            JOptionPane.showMessageDialog(null, e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);                    }        return aCategory;    }

以上是部分代码,欢迎高手们协助解决!

[解决办法]
错误是说的你的索引index不正确
这些方法都是在什么时候调用的?aCategory=getCategory(rs);//getCategory的代码呢?估计就是在这里出错的

if (rs.isLast())
{
JOptionPane.showMessageDialog(null, "已经是最后一条记录了","提示",JOptionPane.INFORMATION_MESSAGE);

}

改成
if (rs.isAfterLast())
{
JOptionPane.showMessageDialog(null, "已经是最后一条记录了","提示",JOptionPane.INFORMATION_MESSAGE);
return; //这里就返回

}

试试看吧


[解决办法]
支持!!!
日的意思就是索引index不正确。

[解决办法]
把附件保存成jpg,bmp太大了
eclipse 没有报错因为你catch了


Java code
 catch(SQLException e)        {           e.printStackTrace();//加这个就可以看到控制台里详细信息了            JOptionPane.showMessageDialog(null, e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);                    } 

读书人网 >J2SE开发

热点推荐