java.sql.SQLException:列索引超出范围,0< 1 [英] java.sql.SQLException: Column Index out of range, 0 < 1

查看:905
本文介绍了java.sql.SQLException:列索引超出范围,0< 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示数据库中的所有图像。我编写了代码但是显示错误java.sql.SQLException:列索引超出范围,0< 1.下面是我的数据库表

I want to display all the images from database. I have written code but that is displaying error java.sql.SQLException: Column Index out of range, 0 < 1. below is the my database table

| application_name | varchar(45)  | 
| application_id   | varchar(10)  | 
| application_path | varchar(500) | 
| application_icon | blob         | 

我想只显示images.below是我的servlet代码

I want to display only images.below is my servlet code

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            response.setContentType("image/jpeg");
            PrintWriter out=response.getWriter();
            try {
                Connection connection= DBUtil.getConnection();
                PreparedStatement preparedStatement=connection.prepareStatement("select application_icon  from application_master");
                ResultSet resultSet=preparedStatement.executeQuery();
                System.out.println("resultSet"+resultSet);
                out.print("<h1>photo</h1>");
                while (resultSet.next()) {
                    out.print("<img width='200' height='200' src="+resultSet.getBlob(0)+ ">  </img>" );
}
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


推荐答案

列索引应从1开始而不是0

Column Index should start from 1 and not 0

http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html#getBlob(INT)


参数:columnIndex - 第一列是1,第二列是2,...

Parameters: columnIndex - the first column is 1, the second is 2, ...

应该是

resultSet.getBlob(1) //first column

这篇关于java.sql.SQLException:列索引超出范围,0&lt; 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆