网站建设
素材下载
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office教程 SEO
网站建设 上海网站建设 域名空间 上海网站设计 上海网站建设 网页设计 广告投放客服QQ:8208442
网站流量
网站建设
当前位置:首页 > 编程开发 > jsp教程

jsp中从数据库中读取图片并保存为图片文件

日期:11-02    来源:中国设计秀    作者:cnwebshow.com

import java.sql.*;
import java.io.*;

public class WriteDB {
        public static void main(String[] args)  {
        Connection conn=null;
        String driver="com.MySQL.jdbc.Driver";//驱动
        String url="jdbc:mysql://127.0.0.1/test?useUnicode=true;characterEncoding=8859_1";// 数据库联接

        try{
               Class.forName(driver).newInstance();
               conn=DriverManager.getConnection(url,"root","");
               File file=new File(args[0]);
               FileInputStream fis=new FileInputStream(file);
               PReparedStatement pstmt=conn.prepareStatement(
                                "insert into picture(picture) values(?)");
               int bytes=(int)file.length();
               System.out.println(bytes);
  
               pstmt.setBinaryStream(1,fis,bytes);//1为插入的参数1,2。。。fileInStream为插入的数据,bytes为字节长度
               pstmt.executeUpdate();

               conn.close();
               fis.close();
     }catch(Exception e){
              System.out.println(e.getMessage());
     }
     }
}

11-02    出处:中国设计秀
艺术设计秀推荐
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明 | 留言板 | 旧版入口