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