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 |
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With