Getting an access violation .. Suggestion??
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();
}
}
Subject
Views
Written By
Posted
Getting an access violation .. Suggestion??
4791
February 13, 2012 05:58AM
2147
February 22, 2012 06:00PM
1950
February 23, 2012 07:24PM
2041
March 18, 2012 06:49AM
1937
March 22, 2012 04:29PM
1765
March 26, 2012 12:07PM
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.