OCIHandleAlloc((dvoid *)envhpp, (dvoid **)&errhpp, OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0);
char sql[255];
sprintf(sql,"%s","insert into scott.emp(empno) values(:9002)");
if (OCIStmtPrepare(stmthpp, errhpp, (text *)sql, (ub4)strlen(sql), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT) != OCI_SUCCESS)
{
cout < < "Create prepare error!" < < sql < < endl;
exit(1);
}
cout < < "Create prepare success!" < < endl;
int i;
OCIBind *hbind1 = NULL;
// OCIBind *hbind2 = NULL;
errhpp=NULL;
i=OCIHandleAlloc((dvoid *)envhpp,(dvoid **)&errhpp,OCI_HTYPE_ERROR,(size_t)0, (dvoid **)0);
ub2 stmt_type;
i=OCIBindByPos(stmthpp,&hbind1,errhpp,1,(dvoid *)&gather.id , sizeof(int),SQLT_INT,NULL,NULL,NULL,0,NULL,OCI_DEFAULT);
// i=OCIBindByPos(stmthpp,&hbind2,errhpp,2,(dvoid *)&gather.name,sizeof(gather.name),SQLT_CHR,NULL,NULL,NULL,0,NULL,OCI_DEFAULT);
//OCIDefineByPos(stmthpp, &bhp1, errhpp, 1, (dvoid *)&gather. id, sizeof(int), SQLT_INT,NULL, &datalen, NULL, OCI_DEFAULT);
i=OCIAttrGet ((dvoid *)stmthpp, (ub4)OCI_HTYPE_STMT, (dvoid *)&stmt_type, (ub4 *)0, (ub4)OCI_ATTR_STMT_TYPE, errhpp);
// 执行 SQL 语句
i=OCIStmtExecute(svcctx, stmthpp, errhpp, (ub4)(stmt_type==OCI_STMT_SELECT?1:0), (ub4)0, (OCISnapshot *)NULL, (OCISnapshot *)NULL, OCI_DEFAULT);
if( ( i)!=OCI_SUCCESS)
{
int errcno;
char errbuf[512]={'\0'};
sb4 errcode;
// 返回一个错误指针和一个 OCI 错误代码
OCIErrorGet((dvoid *)errhpp, (ub4)1, (text *)NULL, &errcode, (ub1 *)errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
errcno = errcode;
cout < < "Oracle execute failed:" < < errbuf < < endl;
OCIHandleFree((dvoid *)envhpp,OCI_HTYPE_ENV);
OCIHandleFree((dvoid *)svcctx,OCI_HTYPE_SVCCTX);
//OCIHandleFree((dvoid *)stmthpp,OCI_HTYPE_STMT);
OCIHandleFree((dvoid *)errhpp,OCI_HTYPE_ERROR);
exit(1);
}
cout < < "Oracle execute success!" < < endl;
OCILogoff(svcctx, errhpp);
OCIServerDetach(srvhpp, errhpp, OCI_DEFAULT);
OCIHandleFree((dvoid *) stmthpp, OCI_HTYPE_STMT);
OCIHandleFree((dvoid *) svcctx, OCI_HTYPE_SVCCTX);
OCIHandleFree((dvoid *) srvhpp, OCI_HTYPE_SERVER);
OCIHandleFree((dvoid *) errhpp, OCI_HTYPE_ERROR);
return 0;
这是我写的关于数据库执行sql语句的程序,可编译能通过,就是跑的时候出现问题说是ora-24333 零迭代器的问题,请牛人榜我看一看程序,到底是哪里有问题,或者是还有什么地方没写完整
char sql[255];
sprintf(sql,"%s","insert into scott.emp(empno) values(:9002)");
if (OCIStmtPrepare(stmthpp, errhpp, (text *)sql, (ub4)strlen(sql), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT) != OCI_SUCCESS)
{
cout < < "Create prepare error!" < < sql < < endl;
exit(1);
}
cout < < "Create prepare success!" < < endl;
int i;
OCIBind *hbind1 = NULL;
// OCIBind *hbind2 = NULL;
errhpp=NULL;
i=OCIHandleAlloc((dvoid *)envhpp,(dvoid **)&errhpp,OCI_HTYPE_ERROR,(size_t)0, (dvoid **)0);
ub2 stmt_type;
i=OCIBindByPos(stmthpp,&hbind1,errhpp,1,(dvoid *)&gather.id , sizeof(int),SQLT_INT,NULL,NULL,NULL,0,NULL,OCI_DEFAULT);
// i=OCIBindByPos(stmthpp,&hbind2,errhpp,2,(dvoid *)&gather.name,sizeof(gather.name),SQLT_CHR,NULL,NULL,NULL,0,NULL,OCI_DEFAULT);
//OCIDefineByPos(stmthpp, &bhp1, errhpp, 1, (dvoid *)&gather. id, sizeof(int), SQLT_INT,NULL, &datalen, NULL, OCI_DEFAULT);
i=OCIAttrGet ((dvoid *)stmthpp, (ub4)OCI_HTYPE_STMT, (dvoid *)&stmt_type, (ub4 *)0, (ub4)OCI_ATTR_STMT_TYPE, errhpp);
// 执行 SQL 语句
i=OCIStmtExecute(svcctx, stmthpp, errhpp, (ub4)(stmt_type==OCI_STMT_SELECT?1:0), (ub4)0, (OCISnapshot *)NULL, (OCISnapshot *)NULL, OCI_DEFAULT);
if( ( i)!=OCI_SUCCESS)
{
int errcno;
char errbuf[512]={'\0'};
sb4 errcode;
// 返回一个错误指针和一个 OCI 错误代码
OCIErrorGet((dvoid *)errhpp, (ub4)1, (text *)NULL, &errcode, (ub1 *)errbuf, (ub4)sizeof(errbuf), OCI_HTYPE_ERROR);
errcno = errcode;
cout < < "Oracle execute failed:" < < errbuf < < endl;
OCIHandleFree((dvoid *)envhpp,OCI_HTYPE_ENV);
OCIHandleFree((dvoid *)svcctx,OCI_HTYPE_SVCCTX);
//OCIHandleFree((dvoid *)stmthpp,OCI_HTYPE_STMT);
OCIHandleFree((dvoid *)errhpp,OCI_HTYPE_ERROR);
exit(1);
}
cout < < "Oracle execute success!" < < endl;
OCILogoff(svcctx, errhpp);
OCIServerDetach(srvhpp, errhpp, OCI_DEFAULT);
OCIHandleFree((dvoid *) stmthpp, OCI_HTYPE_STMT);
OCIHandleFree((dvoid *) svcctx, OCI_HTYPE_SVCCTX);
OCIHandleFree((dvoid *) srvhpp, OCI_HTYPE_SERVER);
OCIHandleFree((dvoid *) errhpp, OCI_HTYPE_ERROR);
return 0;
这是我写的关于数据库执行sql语句的程序,可编译能通过,就是跑的时候出现问题说是ora-24333 零迭代器的问题,请牛人榜我看一看程序,到底是哪里有问题,或者是还有什么地方没写完整
解决方案 »
- 存储过程传递游标错误,请帮忙看看,不胜感谢
- 如何实现oracle的比较
- 怎么从归档模式变成非归档模式,请高手写详细点!
- 求一本Oracle开发的优秀教材
- 我在安装oracle9i后一切正常,能通过delphi(BDE)连接到oracle,但重新启动时报错啊19011
- LINUX下sqlplus的操作
- oracle怎么那么难用?!!
- 急:点Oracle 8i安装程序的时候为什么没有反应?
- 在oracle中,如何向日期型字段添加内容???
- 在Delphi中使用Oracle存储过程是否必须用procedure控件?不能在query中执行?
- 如何编写判断2个数据库之间表中内容是否想等的sql脚本
- 如何动态执行调用存储过程
我是看不出来
:9002是不允许的
不过我自己已经找出答案了,我不用占位符也可以实现insert的插入,问题出错的地方是在
i=OCIStmtExecute(svcctx, stmthpp, errhpp, (ub4)(stmt_type==OCI_STMT_SELECT?1:0), (ub4)0, (OCISnapshot *)NULL, (OCISnapshot *)NULL, OCI_DEFAULT); 这条语句上,stmt_type==OCI_STMT_SELECT?1:0), 因为当不是select的时候,这个参数应该是(ub4)1, 当我改成这样的时候编译就顺利通过了,而且还实现了delete update create,drop 语句的功能的功能,呵呵。
问题已经找到,但是我现在还是不知道占位符是干什么用的,具体用法是干啥?有哪位牛人帮忙解答一下
throws Exception {
String s = "";
File f = new File(fileName);
if (!f.exists()) {
throw new Exception("file doesn't exist....");
}
BufferedReader br = null;
PreparedStatement pstmt = null;
try {
br = new BufferedReader(new InputStreamReader(
new FileInputStream(f)));
String sql = "insert into tbl_report(a,b,c,d)"
+ "values(?,?,?,'2009-12-07')";
pstmt = con.prepareStatement(sql);
// 循环外部准备好prepareStatement;
while ((s = br.readLine()) != null) {
if (s.indexOf("合计") > 0) {
continue;
}
String[] c = s.split("\t");
printArray(c);
if (c.length == 3) {
// 加入批量参数
pstmt.setString(1, c[0]);
pstmt.setString(2, c[1]);
pstmt.setString(3, c[2]);
pstmt.addBatch();
}
}
// 一次执行。
pstmt.executeBatch();
System.out.println("file write back finished");
} catch (Exception e) {
throw e;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}