CREATE TABLE myTable_yq(Document varbinary(max),yq varchar(20))

--SELECT @xmlFileName = 'c:\TestXml.xml'

INSERT INTO myTable(Document)
SELECT * FROM
OPENROWSET(BULK N'E:\20110330110932_61311.jpg', SINGLE_BLOB) AS XMLDATA

INSERT INTO myTable(Document)
SELECT * FROM
OPENROWSET(BULK N'D:\newviewhigh\serializable.txt', SINGLE_BLOB) AS XMLDATA

select * from myTable

select * from myTable_yq

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List; import com.viewhigh.base.databaseconnection.entity.DatabaseConnection;
import com.viewhigh.base.databaseconnection.service.IDatabaseConnectionService;
import com.viewhigh.common.util.DBHelper;
import com.viewhigh.base.databaseconnection.service.impl.DatabaseConnectionServiceImpl; public class InsertBlobTest { public void insert2zwdt(Connection conn) throws Exception{
//IDatabaseConnectionService databaseConnectionService = new DatabaseConnectionServiceImpl();
//DatabaseConnection targetDatabaseConnection = databaseConnectionService
// .getDatabaseConnectionById("40288a5a57d13f0b0157d140652e0003"); //Connection conn = new DBHelper(targetDatabaseConnection) //ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
// oos.writeObject(user);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); //ObjectInputStream ins = new ObjectInputStream(oos); byte[] bytes = bos.toByteArray();
InputStream bis = new ByteArrayInputStream(bytes); //.getConnection();
Statement stmt = conn.createStatement();
PreparedStatement pstmt= null;
conn.setAutoCommit(false);// 取消自动提交 //================================
/*Connection conn = getConnection();
conn.setAutoCommit(false); // 设置手动提交
PreparedStatement pstmt=null; */
File file=new File("D:\\newviewhigh\\serializable.txt");
InputStream in = new FileInputStream(file);
System.out.println("test---------------->");
String sql="insert into myTable_yq(Document,yq) "
+ "values(?,?)"; pstmt=conn.prepareStatement(sql);
pstmt.setBinaryStream(1, bis, file.length());
pstmt.setString(2, "yangqing"); pstmt.execute();
conn.commit();
pstmt.close();
} public static void main(String[] args){ String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; String dbURL="jdbc:sqlserver://localhost:1438;DatabaseName=ah_datai_yd"; String userName="sa"; String userPwd="sa"; try { Class.forName(driverName); Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd); System.out.println("连接数据库成功"); InsertBlobTest ib = new InsertBlobTest(); try {
ib.insert2zwdt(dbConn);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } catch(Exception e) { e.printStackTrace(); System.out.print("连接失败"); } } }

  

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement; import com.viewhigh.base.databaseconnection.entity.DatabaseConnection;
import com.viewhigh.base.databaseconnection.service.IDatabaseConnectionService;
import com.viewhigh.common.util.DBHelper;
import com.viewhigh.base.databaseconnection.service.impl.DatabaseConnectionServiceImpl; public class InsertBlob { //public void insert2zwdt(String xmlFileName, Long index) throws Exception{
public void insert2zwdt(Connection conn) throws Exception{
//IDatabaseConnectionService databaseConnectionService = new DatabaseConnectionServiceImpl();
//DatabaseConnection targetDatabaseConnection = databaseConnectionService
// .getDatabaseConnectionById("40288a5a57d13f0b0157d140652e0003"); //Connection conn = new DBHelper(targetDatabaseConnection)
//.getConnection();
Statement stmt = conn.createStatement();
PreparedStatement pstmt= null;
conn.setAutoCommit(false);// 取消自动提交 //================================
/*Connection conn = getConnection();
conn.setAutoCommit(false); // 设置手动提交
PreparedStatement pstmt=null; */
File file=new File("D:\\newviewhigh\\serializable.txt");
InputStream in = new FileInputStream(file);
System.out.println("test---------------->");
String sql="insert into myTable_yq(Document,yq) "
+ "values(?,?)"; pstmt=conn.prepareStatement(sql);
pstmt.setBinaryStream(1, in, file.length());
pstmt.setString(2, "yangqing");
/* pstmt.setInt(1, index.intValue());
pstmt.setString(2, exData.getStSource());
pstmt.setString(3, exData.getStKey());
pstmt.setString(4, exData.getStVersion());
pstmt.setString(5, exData.getStValue());
pstmt.setString(6, exData.getStOp());
pstmt.setString(7, exData.getStMemo());
pstmt.setBinaryStream(8, in, file.length());
pstmt.setString(9, exData.getStDest()); */ pstmt.execute();
conn.commit();
pstmt.close();
} /*public void insert2own(ExData exData, String xmlFileName, Long index) throws Exception{
File file=new File(xmlFileName);
InputStream in = new FileInputStream(file); DataSending dataSending = new DataSending();
dataSending.setNmSeqId(index.intValue());
dataSending.setStSource(exData.getStSource());
dataSending.setStKey(exData.getStKey());
dataSending.setStVersion(exData.getStVersion());
dataSending.setStValue(exData.getStValue());
dataSending.setStOp(exData.getStOp());
dataSending.setStMemo(exData.getStMemo());
dataSending.setSendDate(new Date());
byte[] data=new byte[]{};
data=inputStreamToByte(in);
dataSending.setBlData(data);
dataSending.setStDest(exData.getStDest());
dataSendingDao.save(dataSending); } */ /*private byte[] inputStreamToByte(InputStream in) throws IOException{
ByteArrayOutputStream baos=new ByteArrayOutputStream();
int ch;
while((ch=in.read())!=-1){
baos.write(ch);
}
byte[] data=baos.toByteArray();
baos.close();
return data;
} */ public static void main(String[] args){ /*InsertBlob ib = new InsertBlob(); try {
ib.insert2zwdt();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/ String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; String dbURL="jdbc:sqlserver://localhost:1438;DatabaseName=ah_datai_yd"; String userName="sa"; String userPwd="sa"; try { Class.forName(driverName); Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd); System.out.println("连接数据库成功"); InsertBlob ib = new InsertBlob(); try {
ib.insert2zwdt(dbConn);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } catch(Exception e) { e.printStackTrace(); System.out.print("连接失败"); } } }

  

sqlserver二进制存储的更多相关文章

  1. mssql sqlserver 可以存储二进制数据的字段类型详解

    转自: http://www.maomao365.com/?p=6738 摘要: 下文将从数据库的数据类型着手,剖析在sqlserver数据库中可以存储二进制数据的数据类型,如下所示: mssql s ...

  2. Sqlserver数据库存储路径的修改

    Sqlserver数据库存储路径的修改 Sqlserver数据库存储路径问题:本系统sqlserver路径默认是存储在C盘目录下的,由于数据会慢慢变大和避免重装系统数据丢失等问题,最好手动将路径设置在 ...

  3. C/C++ 图像二进制存储与读取

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50782792 在深度学习时,制作样本数 ...

  4. 二进制、十六进制理解及int类型二进制存储方式

    二进制 0000 0000 0000 0000 0000 0000 0000 0001 // 2^0 0000 0000 0000 0000 0000 0000 0000 0010 // 2^1 00 ...

  5. 深入理解Sqlserver文件存储之页和应用 (转)

    我们每天都在使用数据库,我们部门使用最多的关系数据库有Sqlserver,Oracle,有没有想过这些数据库是怎么存放到操作系统的文件中的?有时候为了能够设计出最优的表结构,写出高性能的Sqlserv ...

  6. float浮点数的二进制存储方式及转换

    int和float都是4字节32位表示形式.为什么float的范围大于int? float精度为6-7位.1.66*10^10的数字结果并不是166 0000 0000 指数越大,误差越大. 这些问题 ...

  7. xml存储图片 二进制存储图片

    一.保存图片到XML文件 /// <summary> /// 保存图片到XML文件 /// </summary> private void UploadImageToXml() ...

  8. java实现文件转换成二进制存储与取出

    一.功能描述: 将文件转成二进制数据放入数据库中,需要的时候,便可以取出安装与使用. 二.数据库: 建立一个数据库字段存放转成二进制的图片,这个字段有一个要求就是要设置成blob类型的 CREATE  ...

  9. FMDB存储模型对象(以二进制存储)用NSKeyedArchiver archivedDataWithRootObject序列号,NSKeyedUnarchiver unarchiveObjectWithData反序列化(重点坑是sql语句@"insert into t_newsWithChannel (nwesName,newsType) values (?,?)")一定要用占位符

    交友:微信号 dwjluck2013 一.封装FMDB单例 (1)JLFMDBHelp.h文件 #import <Foundation/Foundation.h> #import < ...

随机推荐

  1. 深挖JDK动态代理(二):JDK动态生成后的字节码分析

    接上一篇文章深挖JDK动态代理(一)我们来分析一下JDK生成动态的代理类究竟是个什么东西 1. 将生成的代理类编程一个class文件,通过以下方法 public static void transCl ...

  2. 安装Ubuntu Server18.04(附与CentOS占用体积和Python版本的对比)

    这边只演示一下最新系统的安装过程,设置之类的和以前讲的Kali以及CentOS大同小异:https://www.cnblogs.com/dunitian/p/4822808.html#linux 和C ...

  3. Weblate 2.11安装配置文档

    一.系统环境: OS:CentOS 6.8 x64 Minimal HostName:Weblate IP:192.168.75.153 Python:2.7.13 pip:9.0.1 Weblate ...

  4. Nginx实践篇(2)- Nginx作为静态资源web服务 - 控制浏览器缓存、防盗链

    一.控制浏览器缓存 1. 浏览器缓存简介 浏览器缓存遵循HTTP协议定义的缓存机制(如:Expires;Cache-control等). 当浏览器无缓存时,请求响应流程 当浏览器有缓存时,请求响应流程 ...

  5. Injection with CDI (Part I)

    官方参考:http://docs.jboss.org/weld/reference/latest/en-US/html/index.html https://antoniogoncalves.org/ ...

  6. hbuilder 个推 问题记录

    截止版本日期: 2017/09/19 一,安卓没有角标问题: Android - 2.2+ (支持): 目前仅支持小米(MIUI v5),其它设备调用后无任何效果.官方文档 二,ios角标混乱问题: ...

  7. macOS在virtualenv中使用wxPython报错

    在虚拟的Python环境中运行GUI的软件报错 This program needs access to the screen. Please run with a Framework build o ...

  8. 【CF600E】Lomsat gelral

    题目大意:给定一棵 N 个节点的有根树,1 号节点是树的根节点,每个节点有一个颜色.求对于每个节点来说,能够支配整棵子树的颜色之和是多少.支配的定义为对于以 i 为根的子树,该颜色出现的次数不小于任何 ...

  9. 跟我一起用node-express搭建一个小项目[一]

    我一直以为你要学nodejs你就要掌握很多东西啊!比如js最少得看10本书吧,nodejs书籍得看吧!其实呢,到最后,你会发现,因为工作,或者找工作的需要,什么不学,那些js不懂 也没有很大的关系.所 ...

  10. 关于MySQL锁的详解

    有2种 1.表锁 2.行锁 支持 .innodb支持行锁,表级锁 .myisam只支持表级锁 innodb实现了下面2种标准的行级锁 .共享锁 S LOCK 允许事务读一行数据 .排他锁 X LOCK ...