Trouble with creating a table on jsp page having a column with blob images from MySQL

42
January 13, 2019, at 02:20 AM

I am trying to create a table with a column of text description of an image and a second column with blob images from MySQL.

I've tried this code:

Connection conn = null;
        try {
            conn = DriverManager.getConnection(urldb, user, password);
            String selectSQL = "SELECT pic_name, pic_file FROM picture";
            PreparedStatement pstmt = conn.prepareStatement(selectSQL);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                String fname = rs.getString("pic_name");
                InputStream ffile = rs.getBinaryStream("pic_file");
                out.print("<tr><td>" + fname + "</td><td><img src=\"" + ffile + "\"/></td></tr>");
            };

And the result I get is here:

And then I've also tried this:

Connection conn = null;
        try {
            conn = DriverManager.getConnection(urldb, user, password);
            String selectSQL = "SELECT pic_name, pic_file FROM picture";
            PreparedStatement pstmt = conn.prepareStatement(selectSQL);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                String fname = rs.getString("pic_name");
                InputStream ffile = rs.getBinaryStream("pic_file");
                Blob image = rs.getBlob("pic_file");
                byte imagedata[] = image.getBytes(1, (int) image.length());
                response.setContentType("image/gif");
                OutputStream output = response.getOutputStream();
                output.write(imagedata);
                output.flush();
                output.close();
                out.print("<tr><td>" + fname + "</td><td><img src=\"" + ffile + "\"/></td></tr>");
            };

And this is the second result:

I get on fullscreen the first image from MySQL and that's it.

Any ideas what else to try?

READ ALSO
get hourly results for count in the last 12 hours - MySql

get hourly results for count in the last 12 hours - MySql

I have a big query that is supposed to return the count for rfid's for each product have an association with one order

31
Android Pie 9.0 not playing the audio

Android Pie 9.0 not playing the audio

I am getting the following errors when I run my app on Android 90

63