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. ssh-key 与 git账户配置以及多账户配置,以及通信方式从https切换到ssh

    参考:http://www.cnblogs.com/dubaokun/p/3550870.html 在使用git的时候,git与远程服务器是一般通过ssh传输的(也支持ftp,https),我们在管理 ...

  2. [CTSC2018]暴力写挂——边分树合并

    [CTSC2018]暴力写挂 题面不错 给定两棵树,两点“距离”定义为:二者深度相加,减去两棵树上的LCA的深度(深度指到根节点的距离) 求最大的距离. 解决多棵树的问题就是降维了. 经典的做法是边分 ...

  3. 美丽的webpack-bundle-analyzer

    webpack-bundle-analyzer -- Webpack 插件和 CLI 实用程序,她可以将打包后的内容束展示为方便交互的直观树状图,让我们知道我们所构建包中真正引入的内容: 我们可以借助 ...

  4. MATLAB中mesh函数的使用:基于像素强度画3D密度图(create a 3D density plot based on the pixel intensity:mesh function)

    所用的函数非常简单,只需要用到mesh函数,示例代码如下: Ima=imread('F:\pathto\test.jpg'); surf_ima = surf(rgb2gray(Ima)); %黑色的 ...

  5. 从 date 中取出 小时和分钟进行比较

    public class T1 { public static void main(String[] args) throws ParseException { SimpleDateFormat df ...

  6. java 分隔函数split("",-1)的用途

    转: java 分隔函数split("",-1)的用途 2017年12月14日 11:37:58 jaryle 阅读数:8517   1.如果字符串最后一位有值,则没有区别, 2. ...

  7. ThymeLeaf的eclipse插件安装

    “Help”----“Install New Software...” 输入: http://www.thymeleaf.org/eclipse-plugin-update-site/ 一路Next, ...

  8. SpringBoot整合Freemarker+Mybatis

    开发工具 , 开始 新建工程 .选择Spring Initializr 下一步 下一步,选择需要的组件 ..改一下工程名,Finish ..目录结构 首先,修改pom文件 然后,将applicatio ...

  9. IDEA或Webstorm设置Ctrl+滚轮调整字体大小

    按Ctrl+Shift+A,出现搜索框 输入mouse: 点击打开这个设置:勾选 点击ok,之后就可以通过Ctrl+滚轮 调整字体大小了.

  10. apache2 以及https证书配置

    环境Ubuntu12.04 server 配置 1,首先在进入找到/etc/apache2/apache2.conf的配置文件,里面有包含了较多配置文件的路径如:httpd.conf/ports.co ...