package com.basicSql.scroll_page;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import com.basicSql.connUtil.Conndb; public class SavePic {
public static Connection conn = null;
public static PreparedStatement pStmt = null; /**
* 数据库中加入图片等文件
*/
public static void InsertPic() {
String sql = "insert into teacher(id,name,photo) values(teacher_seq.nextval,?,?)";
try {
conn = Conndb.connOracle();
pStmt = conn.prepareStatement(sql); pStmt.setString(1, "signma"); // 数据库插入图片/word/excel等
File f = new File("src/pic.jpg");
FileInputStream fis = new FileInputStream(f);
pStmt.setBinaryStream(2, fis, (int) f.length()); int n = pStmt.executeUpdate();
System.out.println(n + "条记录插入");
} catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
Conndb.pStmtClose(pStmt);
Conndb.closeConn(conn);
}
} /**
* 从数据库中取出图片等文件
*/
public static void getPic() {
String sql = "select id,name,photo from teacher where id=?";
try {
conn = Conndb.connOracle();
pStmt = conn.prepareStatement(sql); pStmt.setInt(1, 2); ResultSet rs = pStmt.executeQuery();
if (rs.next()) {
FileOutputStream fos = new FileOutputStream(new File("abc.jpg"));
InputStream is = rs.getBinaryStream("photo"); byte[] buffer = new byte[4 * 1024];
int length = 0;
while ((length = is.read(buffer)) != -1) {
fos.write(buffer, 0, length);
}
fos.flush();
fos.close();
is.close();
} } catch (SQLException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
Conndb.pStmtClose(pStmt);
Conndb.closeConn(conn);
}
}
}

  

Oracle数据库插入图片和读取图片的更多相关文章

  1. mysql千万级数据库插入速度和读取速度的调整记录

    一般情况下mysql上百万数据读取和插入更新是没什么问题了,但到了上千万级就会出现很慢,下面我们来看mysql千万级数据库插入速度和读取速度的调整记录吧. 1)提高数据库插入性能中心思想:尽量将数据一 ...

  2. PLSQL往Oracle数据库插入中文后变为问号 和 启动PLSQL时提示NLS_LANG在客户端不能确定的解决办法

    PLSQL往Oracle数据库插入中文后变为问号 和 启动PLSQL时提示NLS_LANG在客户端不能确定的解决办法 1.检查服务器的字符编码 Select * from V$NLS_PARAMETE ...

  3. 使用mybatis向oracle数据库插入数据异常

    遇到了使用mybatis向oracle数据库插入数据异常的问题, 具体的报错如下:org.springframework.jdbc.UncategorizedSQLException: ### Err ...

  4. MySQL数据库写入图片并读取图片显示到JLabel上的详解

    相较于Oracle,MySQL作为一个轻量级的开源的数据库,可谓是大大简化了我们的操作.这次我就来写一个关于数据库存入图片,获取图片的例子吧,也为了今后的复习使用.(我们一般采取存入路径的方式,而不是 ...

  5. SQL 2008存储图片和读取图片

    用SQL Server存储文字数据非常easy实现,假设用SQL Server存储图片呢?大家有没有实现思路呢?如今我用一个Demo来为大家提供一种在SQL Server中存储图片的思路. 场景:在s ...

  6. 160304-01、mysql数据库插入速度和读取速度的调整记录

    需求:由于项目变态,需要在一个比较短时间段急剧增加数据库记录(两三天内,由于0增加至5亿).在整个过程调优过程非常艰辛 思路: (1)提高数据库插入性能中心思想:尽量将数据一次性写入到Data Fil ...

  7. img src某个php文件输出图片(回复更改图片readfile读取图片等)

    在论坛我们经常看到一回复图片就更改等,这功能是怎么实现的呢,其实更验证码道理相同. 新建文件 randimage.php 加入以下代码: <?php $dir='../../images/'; ...

  8. Oracle数据库插入数据出错:ORA-06550

    wpf应用调用oracle的存储过程,出错“ORA-06550:参数个数或参数类型出错”,如下图: 反复检查,存储过程的参数个数和参数类型都没错,觉得非常蹊跷.最后终于解决, 原因是当参数的值为nul ...

  9. 解决关于:Oracle数据库 插入数据中文乱码 显示问号???

    问题: oracle数据库,通过接口插入的中文数据乱码,中文变成了问号??? 解决方案: 计算机=>属性=>高级系统设置=>环境变量=>新建 变量名:NLS_LANG 值:SI ...

随机推荐

  1. tar备份系统

    一.概述 前几天我通过SSH正在调戏汤姆猫(tomcat)的时候,服务器上CentOS突然挂了.开机grub,使用光盘linux rescue修复提示找不到linux分区,然后想mount硬盘备份系统 ...

  2. com.transfer.www

    package com.transfer.www; import java.io.IOException; import java.io.PrintWriter; import javax.servl ...

  3. 生产者/消费者问题的多种Java实现方式--转

    实质上,很多后台服务程序并发控制的基本原理都可以归纳为生产者/消费者模式,而这是恰恰是在本科操作系统课堂上老师反复讲解,而我们却视而不见不以为然的.在博文<一种面向作业流(工作流)的轻量级可复用 ...

  4. Editing and Deleting Data

    Editing and Deleting Data In the previous chapter we've come to learn how we can use the zend-form a ...

  5. Understanding the Router

    Understanding the Router Our module is coming along nicely. However, we're not really doing all that ...

  6. Android ADB启动失败 ADB server out of date

    调试Android程序时总提示ADB未运行,转到命令行方式下启动ADB, adb kille-server停止ADB, 然后再运行adb start-server 随后提示: adb server i ...

  7. 并发容器之CopyOnWriteArrayList(转载)

    Copy-On-Write简称COW,是一种用于程序设计中的优化策略.其基本思路是,从一开始大家都在共享同一个内容,当某个人想要修改这个内容的时候,才会真正把内容Copy出去形成一个新的内容然后再改, ...

  8. 仿百度自动补全jquery

    新建index.html文件,直接复制下面代码到新建的文件index.html里面,用浏览器访问,仅用于参考: <!doctype html><html><meta ch ...

  9. Apache Shiro 使用手册

    http://kdboy.iteye.com/blog/1154644 (一)Shiro架构介绍 一.什么是Shiro  Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加 ...

  10. HashMap的一般用法以及遍历方法

    private Map<Integer,String> selected = new HashMap<Integer,String>(); selected.put(key,v ...