前段时间尝试用了ODBC和ADO连接并上传图片都没能超过32K限制,最近用了OO4O终于解决了这个问题。方法及代码如下:
1 下载客户端
ORACLE官方下载链接:http://download.oracle.com/otn/other/ole-oo4o/ODAC101040.exe
2 安装并配置:
解压后,双击/disk/setup.exe,一路下一步,直到出现如下界面,并按图的顺序一路配置:
图1 直接点下一步
图2 点下一步
图3 在文本内输入服务名
........................
实在贴不动了,依照顺序输入:协议,远程数据库IP,端口,用户名,口令然后点确定,完成 本地NET服务名配置(也可以直接跳过此配置,在以后通过开始->程序->Oracle - OraClient10g_home1->Configuration and Migration Tools->Net Configuration Assistant 工具配置)。
3. 代码:(该代码调试通过)
#include "stdafx.h"
#include <stdlib.h>
#include <oracl.h>
#include <iostream.h>
#include <fstream.h>
// Example for OParameter, OParamArray Raw example
int main()
{
//Initialize oo4o, connect, execute sql
OStartup();
ODatabase odb("NLV", "NLV_GUEST", "GUEST");
if (!odb.IsOpen())
{
cout <<"Connect Error: "<<odb.GetErrorText()<<endl;
return 1;
}
else cout << "Connect DataBase OK!" << endl;
//Init Parameters
OParameterCollection params = odb.GetParameters();
OParameter hpzl = params.Add("hpzl", "5", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter hphm = params.Add("hphm", "粤C00009", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter wfsj = params.Add("wfsj", "2008-08-19 09:04:45", OPARAMETER_INVAR, OTYPE_DATE);
OParameter wfxw = params.Add("wfxw", "16037", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter wfdd = params.Add("wfdd", "60108", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter wfdz = params.Add("wfdz", "新增路口", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter cjjg = params.Add("cjjg", "3707860100", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter sjly = params.Add("sjly", "2", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter zplx = params.Add("zplx", "1", 1, OPARAMETER_INVAR, OTYPE_CHAR);
OParameter sbbh = params.Add("sbbh", "37078610045", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter cdbh = params.Add("cdbh", "", OPARAMETER_INVAR, OTYPE_VARCHAR2);
OParameter clsd = params.Add("clsd", 55, OPARAMETER_INVAR, OTYPE_NUMBER);
OParameter dcxs = params.Add("dcxs", 1, OPARAMETER_INVAR, OTYPE_NUMBER);
OParameter kcxs = params.Add("kcxs", 1, OPARAMETER_INVAR, OTYPE_NUMBER);
OParameter xcxs = params.Add("xcxs", 1, OPARAMETER_INVAR, OTYPE_NUMBER);
OParameter dczfxs = params.Add("dczfxs", 1, OPARAMETER_INVAR, OTYPE_NUMBER);
OParameter kczfxs = params.Add("kczfxs", 1, OPARAMETER_INVAR, OTYPE_NUMBER);
OParameter xczfxs = params.Add("xczfxs", 1, OPARAMETER_INVAR, OTYPE_NUMBER);
OParameter zdxs = params.Add("zdxs", 1, OPARAMETER_INVAR, OTYPE_NUMBER);
// write data to BLOB
fstream fs;
fs.open("c://more_than_32k.jpg", ios::in);
fs.setmode(filebuf::binary);
fs.seekg(0, ios::end);
unsigned long filesize = fs.tellg();
fs.seekg(0, ios::beg);
cout <<"filesize: "<<filesize<<endl;
OBlob b_lob(odb);
unsigned long optchunk = b_lob.GetOptimumChunkSize();
unsigned int bufsize = ((int)(32768/optchunk)) *optchunk;
unsigned char * buffer;
buffer = (unsigned char *)malloc(bufsize);
unsigned long totalwritten = 0;
unsigned long amtread = 0;
int piecetype = OLOB_FIRST_PIECE;
if (filesize <= bufsize)
piecetype = OLOB_ONE_PIECE;
else
b_lob.EnableStreaming(filesize);
while(totalwritten != filesize)
{
fs.read(buffer, bufsize);
amtread = fs.gcount();
b_lob.Write(buffer, amtread, piecetype);
totalwritten = totalwritten + amtread;
if ((filesize - totalwritten)<=bufsize)
piecetype = OLOB_LAST_PIECE;
else
piecetype = OLOB_NEXT_PIECE;
}
b_lob.DisableStreaming();
fs.close();
OParameter zjwj1 = params.Add("zjwj1", b_lob, OPARAMETER_INVAR, OTYPE_BLOB);
OParameter zjwj2 = params.Add("zjwj2", b_lob, OPARAMETER_INVAR, OTYPE_BLOB);
OParameter zjwj3 = params.Add("zjwj3", b_lob, OPARAMETER_INVAR, OTYPE_BLOB);
OParameter zxjg = params.Add("zxjg", 19, OPARAMETER_INOUTVAR, OTYPE_UINT);
OValue oval;
oval.Clear();
zjwj2.SetValue(oval);
zjwj3.SetValue(oval);
unsigned long size = b_lob.GetSize();
printf("blob size = %d/n", size);
oresult r = odb.ExecuteSQL("BEGIN nlv_cache.nlv_package.pro_tgs(:hpzl, :hphm, :wfsj, :wfxw, :wfdd, :wfdz, :cjjg, :sjly, :zplx, :sbbh, :cdbh, :clsd, :dcxs, :kcxs, :xcxs, :dczfxs, :kczfxs, :xczfxs, :zdxs, :zjwj1, :zjwj2, :zjwj3, :zxjg);END;");
if (r == OFAILURE)
{
cout <<"Execute Error: "<<odb.GetErrorText()<<endl;
return 1;
}
int ret;
zxjg.GetValue(&ret);
printf("ZXJG = %d/n", ret);
odb.Close();
return 0;
}
4. 完成