Bug #69925 PreparedStatement
Submitted: 5 Aug 2013 7:28 Modified: 5 Aug 2013 13:12
Reporter: Vikash Kumar Gupta Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / C++ Severity:S3 (Non-critical)
Version: OS:Linux
Assigned to: CPU Architecture:Any
Tags: C++, connector

[5 Aug 2013 7:28] Vikash Kumar Gupta
Description:
When I'm making a sql query in the MySQL using the Prepared Statement, I get an MySQL an run_time error like "ERROR: MySQL_Connection::prepareStatement(const sql::SQLString& sql, int autoGeneratedKeys)". While the program code doesn't give any syntax error during compile time.
The complete program source code is as : 

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

How to repeat:
Please help me where I'm wrong. Thanks...
[5 Aug 2013 12:00] MySQL Verification Team
Running test case

Attachment: connector_stm.png (image/png, text), 74.96 KiB.

[5 Aug 2013 12:03] MySQL Verification Team
Thank you for the bug report. I could repeat using mysql-connector-c++-noinstall-1.1.3-winx64. I created the table, compiled your test case, running twice without an error message (see picture attached). Thanks.
[5 Aug 2013 12:13] Vikash Kumar Gupta
Sir, I'm working on Unix based system(Ubuntu 10.04 LTS) and I'm generating the application by running following commands:
1)- $g++ -Wall -c preparedstmt_test.cpp -lmysqlcppconn
2)- $g++ -Wall .o preparedstmt_test preparedstmt_test.cpp
3)- $./preparedstmt_test

after running last command i got the following error : 

# ERR: SQLException in preparedstmt_test.cpp(main) on line » 36
# ERR: MySQL_Connection::prepareStatement(const sql::SQLString& sql, int autoGeneratedKeys) (MySQL error code: 0, SQLState: )
[5 Aug 2013 13:12] Vikash Kumar Gupta
I'm sorry Sir, the above command is wrong right command is as :
1)- $g++ -Wall -c preparedstmt_test.cpp -lmysqlcppconn
2)- $g++ -Wall -o preparedstmt_test preparedstmt_test.cpp -lmysqlcppconn
3)- $./preparedstmt_test

after running last command I got the following error : 

# ERR: SQLException in preparedstmt_test.cpp(main) on line » 36
# ERR: MySQL_Connection::prepareStatement(const sql::SQLString& sql, int autoGeneratedKeys) (MySQL error code: 0, SQLState: )