问题
ResultSet *search;
....
....
search= prepareStatement->executeQuery();
while (search->next())
{
cout << "Email Found: " << search->getString("EmailColumn") << endl; //crashes here
}
From the code above, calling getString() function actually gets the value from the database. But then it crashes the program. It displays the value then crashes the program.
I discovered the problem but couldn't fix it. I can't tell if this is a bug or something else.
The problem only happens when the length of the value in the EmailColumn column is more or equals to 16. No error if the length of the value is less or equals to 15.
Any solution or workarounds for this?
回答1:
I solved it. The solution is to build your own C++ Connector and use the dll files it compiles. The dll distributed by Oracle was made with a different version of Visual Studio compiler that I am currently using. The first answer here will show you how to build it yourself. MySQL Connector C++ 64bit build from source in Visual Studio 2012?
回答2:
I had almost the same problem (and realized too late that Oracle is not supporting the library for Windows anymore). The following workaround worked for me:
ResultSet *search;
....
....
search= prepareStatement->executeQuery();
while( search->next() )
{
string const * theString =
new string( search->getString( "EmailColumn") );
cout << *theString << endl;
operator delete( theString );
theString = nullptr;
}
My guess is that by this construction VisualStudio 2015 is compiling code that is not calling the destructor std::string::~string() (which caused the crash for my application) for a string that is created by the library via ResultsSet::getString().
来源:https://stackoverflow.com/questions/30476969/resultset-getstring-crashes-when-value-is-16