gpt4 book ai didi

c++ - 使用 OCCI 在 Oracle 数据库中插入多行

转载 作者:搜寻专家 更新时间:2023-10-31 01:58:08 30 4
gpt4 key购买 nike

这是我第一次体验 OCCI,所以如果答案很明显,请原谅。

我有一个 Statement 对象,以通常的方式创建:

string sqlStatement = "INSERT INTO data_tab VALUES(:id, :name, :number, :when)";
m_stmt = m_conn->createStatement(sqlStatement);

m_stmt->setMaxIterations(100);

然后我需要遍历一些我应该插入到数据库中的对象:

for(size_t i = 0; i < data.size(); ++i)
{
m_stmt->setInt(1, i);

try {
m_stmt->setString(2, data[i].client());
}
catch(SQLException& e)
{
cerr << "setString(): " << e.what();
exit(1);
}

m_stmt->setDouble(3, data[i].number());
m_stmt->setDate(4, data[i].when());

// ...
// Checks if maxIterations is lesser than data size,
// oteherwise calls executeUpdate and other kind of
// boilerplate code.
// ...

m_stmt->addIteration();
}

但是代码在 setString 方法中出错,输出如下:

setString(): ORA-32132: maximum iterations cannot be changed

我相信我应该得到这个错误是我在 setXXX 方法之后调用 setMaxIterations 但我没有这样做。我做错了什么?

最佳答案

您应该在设置可变长度参数之前调用 setMaxParamSize():

m_stmt->setMaxParamSize(2, 1000) // or whatever is the max length of your string.

关于c++ - 使用 OCCI 在 Oracle 数据库中插入多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4547795/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com