MySQL Forums
Forum List  »  Connector/C++

Getting an access violation .. Suggestion??
Posted by: Rajesh khan
Date: February 13, 2012 05:58AM

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();
}
}

Options: ReplyQuote


Subject
Views
Written By
Posted
Getting an access violation .. Suggestion??
4791
February 13, 2012 05:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.