MySQL Forums
Forum List  »  Connector/C++

MySQL Connector : Prepared Statement in C++
Posted by: Vikash Kumar Gupta
Date: August 02, 2013 04:11AM

There is anyone who help me to find where i'm wrong in my code because i'm new in c++ development. This example code gives following error "ERROR: MySQL_Connection::prepareStatement(const sql::SQLString& sql, int autoGeneratedKeys)".
The example code is here :
/* Standard C++ includes */
#include <cstdlib>
#include <iostream>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/prepared_statement.h>
using namespace std;
using namespace sql;
int main(void)
{
try {
Driver *driver;
Connection *con;
PreparedStatement *pstmt;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "");
con->setAutoCommit(false);
/* Connect to the MySQL test database */
con->setSchema("test");
/* Create a prepared query */
pstmt = con->prepareStatement("INSERT INTO City(CityName) VALUES (?)");
pstmt->setString(1, "Denmark");
pstmt->execute();

con->commit();
con->setAutoCommit(true);

delete pstmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line ยป " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL Connector : Prepared Statement in C++
5203
August 02, 2013 04:11AM


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.