如何读取oracle数据库中的图像并显示出来?或将现有图像存入数据库中??用java或VC如何操作?请详细一些,多谢了,多谢

解决方案 »

  1.   

    给你个例子,在JSP页面读取并显示oralce数据库表里的图片
    <%@ page language="java" import="java.sql.*,java.util.*"%>
    <%@ page import="java.io.*" %>
    <%@ page import="java.text.*" %>
    <%@ page import="java.lang.*" %>
    <html>
    <body>
    <%
    String sql = "select BLOB_COLUMN from UTL_LOB_TEST where id=2";
    ResultSet rs = null;
    try {
         Connection conn=null;
         Statement  stmt=null;
         Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
         conn = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.131)(PORT = 1521)))(CONNECT_DATA = (SID = STUDY)(SERVER = DEDICATED)))","zhu","zhu");
         stmt = conn.createStatement();
         rs = stmt.executeQuery(sql);
        }catch (SQLException e)
          {System.out.println(e);}
    try {
         if (rs.next())
            {
             response.setContentType("image/jpg");
             ServletOutputStream myjpeg = response.getOutputStream();
             byte [] image =rs.getBytes(1);
             myjpeg.write(image);
             myjpeg.flush();
             myjpeg.close();
            }
         } catch (Exception e)
            {System.out.println(e);
             PrintWriter toClient = response.getWriter();
                response.setContentType("text/html;charset=gb2312");
                toClient.write("无法打开图片!");
                toClient.close();
            } finally {
                //stmt.close();
                //conn.close();
            }
    %>
    </body>
    </html>