论坛首页 » Java,C/C++,Shell,Php,Web 交流区 » Java » [原创]把图片保存在数据库中
RSS WAP
统计:回贴:0   阅读:136   最后更新:2007-03-02 00:00
标题: [原创]把图片保存在数据库中
iwlk

头衔:灭天使者
等级:一级用户
精华:40
帖子:41 / 26
积分:0

在线时间:2143分
注册时间:2007-01-01 00:00
最后登录:2008-01-19 15:27
鲜花(24)   鸡蛋(33)
#1
[原创]把图片保存在数据库中
private static String BYTEMAP[];
static
{
  BYTEMAP = new String[256];
  int i = 0;
  do
  {
    BYTEMAP = String.valueOf(Integer.toHexString(i / 16)) + String.valueOf(Integer.toHexString(i % 16));
  } while (++i < 256);
}

public static String cite(byte abyte0[])
{
  if (abyte0 == null)
  {
    return "null";
  }
  StringBuffer stringbuffer = new StringBuffer("0x");
  for (int i = 0; i < abyte0.length; i++)
  {
    stringbuffer.append(BYTEMAP[0xff & abyte0]);
  }
  return stringbuffer.toString();
}

public static void main(String args[])
{
  java.sql.Statement statement=null;
  byte picture[]=null;
  ......
  statement.executeUpdate("INSERT INTO tab1(picture)VALUES("+cite(picture)+")");
  .....
}

搜索更多相关主题的帖子:
发表于:2007-03-02 18:46