Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

Getting an access violation .. Suggestion?? (no replies)

$
0
0
I am using Visual studi 2010 and added "MySQL Connector C++ 1.0.5" header and library files to it. The code i am using is below. The problem is I get the error

"Unhandled exception at 0x5bcdad4a (msvcp100d.dll) in mysqlite.exe: 0xC0000005: Access violation reading location 0xccccccd0"

at the line while (res->next()) the first result gets displayed then the error shows up Why is that

My code is
#include <stdlib.h>
#include <iostream>

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

int main(){

sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;

try{
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "admin");
con->setSchema("test");

stmt = con->createStatement();
stmt->execute("insert into example values(4,'four'),(5, 'five')");
delete stmt;

pstmt = con->prepareStatement("select * from example");
res = pstmt->executeQuery();
while (res->next())
std::cout<<res->getInt("id")<<" "<<res->getString("data")<<std::endl;
delete res;
delete pstmt;

pstmt = con->prepareStatement("delete from example where id=?");
pstmt->setInt(1,4);
pstmt->executeUpdate();
pstmt->setInt(1,5);
pstmt->executeUpdate();

delete pstmt;

delete con;
}catch(sql::SQLException &e){
std::cout<<e.what();
}
}

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>