【ZT】Mysql保存word,jpg
来源:互联网 发布:mac如何强制关机 编辑:程序博客网 时间:2024/05/16 09:01
【方法一:使用LongBlob 不丢失原有格式】
http://topic.csdn.net/u/20100409/00/0620229f-7f92-464d-bca6-6db00dcc799f.html
mysql表里面搞个longblob字段保存word
代码:
1)上传
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://localhost/test?user=root&password=root&useUnicode=true&characterEncoding=gbk";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
stmt.execute("insert into test(myid) values (5)");
stmt.close();
PreparedStatement pstmt = null;
String sql = "";
File file = new File("c:\\kick.jpg");
InputStream photoStream = new FileInputStream(file);
sql = " UPDATE test SET photo = ? WHERE myid = 5" ;
pstmt = conn.prepareStatement(sql);
pstmt.setBinaryStream(1, photoStream, (int)file.length());
pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
2)下载:
PreparedStatement pst = ..... //省略获取Connection及查询的sql
ResultSet rs = pst.executeQuery();
InputStream is = rs.getBinaryStream(1); //1表示你的word字段在结果集中的索引号
FileOutputStream fos = new FileOutputStream("path");
byte [] buf = new byte[1024];
while(is.read(buf)!=-1){
fos.write(buf);
}
//close省略
mysql表里面搞个longblob字段保存word
代码:
1)上传
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://localhost/test?user=root&password=root&useUnicode=true&characterEncoding=gbk";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
stmt.execute("insert into test(myid) values (5)");
stmt.close();
PreparedStatement pstmt = null;
String sql = "";
File file = new File("c:\\kick.jpg");
InputStream photoStream = new FileInputStream(file);
sql = " UPDATE test SET photo = ? WHERE myid = 5" ;
pstmt = conn.prepareStatement(sql);
pstmt.setBinaryStream(1, photoStream, (int)file.length());
pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
2)下载:
PreparedStatement pst = ..... //省略获取Connection及查询的sql
ResultSet rs = pst.executeQuery();
InputStream is = rs.getBinaryStream(1); //1表示你的word字段在结果集中的索引号
FileOutputStream fos = new FileOutputStream("path");
byte [] buf = new byte[1024];
while(is.read(buf)!=-1){
fos.write(buf);
}
//close省略
【方法二:转换成二进制,在保存,容易丢失原有word格式】
- 【ZT】Mysql保存word,jpg
- MySQL保存jpg图片 测试通过
- asctionscript3 保存jpg格式。
- asp.net 保存 jpg
- 保存Word
- actionscript3保存为jpg格式
- HBITMAP 保存为JPG格式
- 将网页保存为jpg
- CDR怎么保存JPG格式
- 保存网页内容至word,相关内容导入mysql
- word 保存时 不能保存
- jpg转word的简单方法
- 将JPG文件转换成word文档
- C#提高保存jpg图像的质量
- 截屏并保存JPG图片
- flex 保存控件为jpg或png
- 使用GDI+保存带品质的JPG
- "画图"不能保存为JPG格式文件
- [ZT] ConcurrentHashMap解析
- Win7 运行PHPnow 权限问题
- 【ZT】什么是DOCTYPE 它对网页起何作用?
- 【ZT】解决apache Web服务器网页乱码
- 【ZT】Eclipse Tomcat插件的配置, 及 Tomcat 的配置 ( 谁来教我?)
- 【ZT】Mysql保存word,jpg
- HTML供文件上传功能浏览功能的元素是<input/>的file类型
- 【ZT】Jsp/Servlet:实现文件上传与下载【一】
- 【ZT】Jsp/Servlet:实现文件上传与下载【二】
- 【ZT】Jsp/Servlet:实现文件上传与下载【三】
- java目录文件说明
- 【ZT】Struts 2中实现文件下载(修正中文问题)
- 【ZT】jsp文件下载,解决中文名称乱码
- 【ZT】使用JQuery的each