_JSP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

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

作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0

本篇关键词:图片一个文件保存

  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为插入的参数12。fileInStream为插入的数据bytes为字节长度
                 pstmt.executeUpdate();

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


    希望这篇从数据库中读取一个图片并保存为一个图片文件的文章能够对您有所帮助,如果您觉得这篇网站维护教程有用的话,别忘了推荐给您的朋友哦!如果您有好的经验方法,不妨拿出来和大家一起分享:假如每个人都拿出一个经验,那么我们都将额外的获取一堆他人的经验。
请记住本站永久域名:(黑客防线网安服务器维护方案维护基地)Www.Rongsen.Com.Cn
    黑客防线网安服务器维护方案本篇连接:http://kj.rongsen.com.cn/show-16354-1.html
网站维护教程更新时间:2012-04-07 00:20:28  【打印此页】  【关闭
0
顶一下
0
踩一下
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer