unable to display all info from the database through jsp

前端 未结 1 1082
臣服心动
臣服心动 2021-01-24 23:12

My requirement is to insert artist details and his picture through jsp into oracle database and retrieve back information and picture through another jsp program.

artist

1条回答
  •  囚心锁ツ
    2021-01-24 23:53

    As of version 6, Java SE provides JAXB by which the bytes may be converted in to base64 string. Here also you may convert the image byte[] into base 64 string and it can be displayed using the html tag specifying the src data as base 64 i.e. src="data:image/png;base64,.

    Modify your code as follows :

    <%
                PreparedStatement ps=con.prepareStatement("select * from artist");
                ResultSet rs=ps.executeQuery();
                while(rs.next()){ %>
                
    artist fast name:<%=rs.getString(1) %>
    artist middle name:<%=rs.getString(2) %>
    artist last name<%=rs.getString(3) %>
    artist job<%=rs.getString(4) %>
    artist image <% Blob bl=rs.getBlob(5); byte[] image=bl.getBytes(1, (int)bl.length()); %> bye
    <% } con.close(); %>

    Here is another sample jsp page for getting a clear idea :

    <%@page import="java.awt.image.BufferedImage"%>
    <%@page import="javax.imageio.ImageIO"%>
    <%@page import="java.io.*"%>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    
    
    
    
    Insert title here
    
    
    <%
    BufferedImage bImage = ImageIO.read(new File("/home/visruth/Desktop/Visruth.jpg"));//give the path of an image
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write( bImage, "jpg", baos );
    baos.flush();
    byte[] imageInByteArray = baos.toByteArray();
    baos.close();
    String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);
    %>
    
    

    As of v6, Java SE provides JAXB

    Visruth.jpg not found

    0 讨论(0)
提交回复
热议问题