数据是8个POINT, 结果应该是8行,现在却显示了32行,为什么重复显示这么多次?请高手指教!
void restorePoint (string s)
{ string sqlStmt =
"select point_id, x, y, z from point where part_id =:x";
stmt = conn->createStatement (sqlStmt);
stmt->setString (1, s);
ResultSet *rset = stmt->executeQuery ();
int point_id[5];
ub2 point_id_len[5];
rset->setDataBuffer(1, &point_id, OCCIINT, (ub2)
sizeof(point_id[0]), &point_id_len[0]);
double coorx[5];
ub2 coorx_len[5];
rset->setDataBuffer(2, &coorx, OCCIFLOAT, (ub2)
sizeof(coorx[0]), &coorx_len[0]);
double coory[5];
ub2 coory_len[5];
rset->setDataBuffer(3, &coory, OCCIFLOAT, (ub2)
sizeof(coory[0]), &coory_len[0]);
double coorz[5];
ub2 coorz_len[5];
rset->setDataBuffer(4, &coorz, OCCIFLOAT, (ub2)
sizeof(coorz[0]), &coorz_len[0]);
cout << "point_id coorx coory coorz " << endl;
cout << "======== ===== ===== ===== " << endl;
int rowCounter = 0;
try {
while (rset->next(5)) {
for (int i = 0; i < 5; i++)
cout<<point_id[i]<< " "<<coorx[i]<< " " <<coory[i]<< " " <<coorz[i]<<endl;
rowCounter += 5;
}
int remainingRows = rset->getNumArrayRows() - rowCounter;
for (int i = 0; i < remainingRows; i++)
cout<<point_id[i]<< " "<<coorx[i]<< " " <<coory[i]<< " " <<coorz[i]<<endl;
}
catch(SQLException ex) {
cout << "Exception thrown for next() method" << endl;
cout << ex.getErrorCode() << endl;
}
cout << "Restore - Success" << endl;
stmt->closeResultSet (rset);
conn->terminateStatement (stmt);
}
2 个解决方案
#1
up
#2
the code looks right at first glance. use SQL* to make sure there are only 8 points in table point or try to use SELECT DISTINCT.
#1
up
#2
the code looks right at first glance. use SQL* to make sure there are only 8 points in table point or try to use SELECT DISTINCT.