图片可以用bytea类型(也可大对象)
代码看你要用什么语言了

解决方案 »

  1.   

    bytea类型对应java中的什么方法啊
    例如:  get???()
      

  2.   

    get不来的,要读取图片字节流存入数据库中,显示图片也要自己写方法的。
    如果用大对象可以调用大对象处理函数(参见http://fanqiang.chinaunix.net/a2/b3/20010421/231518.html)
    不过一般大对象是存放比较大的文件的,存放图片好像没必要用这个。
      

  3.   

    下面是java读取图片存入数据库的(bytea类型):
    如果图片不在WEB服务器上,需要上传服务器,然后下面是JAVA操作代码(数据库中是bytea类型):
    String photopath="详细的文件路名(包含图片名)" 
    File file = new File(photopath);
    FileInputStream fis = new FileInputStream(file);
    int fileLength = (int)file.length(); 
    photoStr = "insert into tab_photo(id,photopath) values('" + id + "',?)";
    statement = conn.prepareStatement(photoStr); //conn 是建立的数据库连接
    statement.setBinaryStream(1, fis, fileLength);
    statement.executeUpdate();
    statement.close();
    fis.close();
      

  4.   

    我写过一个用于显示图片的jsp,你再你的jsp中引用它就行了,这样引用:
    <img name="picshow" width="100" height="133" src="showImage.jsp?id=<%=id%>" title="图像预览"/>,其中的参数id是显示图片的jsp即showImage.jsp中用于唯一标志某个图片的一个参数,在showImage.jsp中要用这个id参数将所要显示的图片读出来,showImage.jsp中开始的数据库连接部分你应该改一下,我是tomcat连接池的,估计与你的不一样,数据库查询语句自己改。
    showImage.jsp:<%@page contentType="text/html;charset=GBK" language="java" %>
    <%@ page buffer="200kb" %>
    <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>//这两行struts标签,不用可以删掉
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>//
    <%@page import="java.util.*" %>
    <%@page import="java.sql.*" %>
    <%@page import="javax.naming.*" %>
    <%@page import="com.wellsoon.police.db.*" %>
    <%@page import="java.io.*"%>     
    <%    
    try  {  
    String  id=request.getParameter("id");//此处联数据库  
    Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            Context initCtx = new InitialContext();
            Context ctx = (Context) initCtx.lookup("java:comp/env");
            javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/police");
            conn = ds.getConnection();
            //stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
        }
        catch (Exception e) {
            System.out.println(e.toString());
        }
    String  cmd="select case when photo is null then (select photo from tab_prephoto where id='aaa') else photo end from tab_photo WHERE  id  ='"+ id + "'";
    System.out.println("cmd.................=" + cmd);
    stmt=conn.prepareStatement(cmd);    
    rs  =  stmt.executeQuery();byte[] Buffer=new byte[1024*10];
    InputStream InData=null;
    OutputStream outData=null;
    int iSize;
    if(rs.next())
    {
    outData=response.getOutputStream();
    InData=rs.getBinaryStream("photo");
    response.setContentType("image/gif,jpeg");
    while(true)
    {
    iSize=InData.read(Buffer);
    if(iSize==-1)
    {
    break;
    }
    outData.write(Buffer,0,iSize);
    }
    outData.flush();
    response.flushBuffer();
    }else {};
    rs.close();
    InData.close();
    outData.close();try {
    stmt.close();
    conn.close();
      }
      catch (Exception e1) {
    out.println(e1.toString());
      }
      finally {
    try {
      if(stmt != null) stmt.close();
      if(!conn.isClosed()) conn.close();
    }
    catch (Exception e2) {
      out.println(e2.toString());
    }
      }

    catch(Exception  e)  
    {  System.out.println("error while close connection = "+e.toString());}  
     
      
    %>
      

  5.   

    对了,有没有将图片读出来显示在jsp里的例子啊
      

  6.   

    我用的是jsp smartupload组件上传图片的,用的它的upBean.setMaxFileSize()来限制上传图片大小的,你要用其它方法自己搜索看看吧
      

  7.   

    可以用上传组件比如jsp smartupload,struts自带也有,自己到网上搜索,相关资料很多
      

  8.   

    进来看了一下,怎么好像说相声啊。
    我们公司都是用bytea来存图片和铃声的二进制数据。用的java,所以比较简单。