problem using prepared statement
I want to make insert along prepared statements and i'm getting an error that i can understand... I use 2 functions to make the inserts. In the first i load on server the preparedstatement. This works perfect. In the second i fill the variables and i execute the query. Then when execute instruccion is being executed i get a sql exception.
The exception is this:
Using unsupported buffer type: 4544336 (parameter: 3) (MySQL error code: 2036, SQLState: HY000)
The field id have auto_increment activated. Prepared statement is a global variable called _pstmt. The code is this:
int ControladorDades::preparaInsertaServeis(){
try{
_pstmt = _con->prepareStatement((string)"INSERT INTO Serveis (id, numServei, dia, mes, any, hora, minut, idSoci, idTarifa) VALUES (NULL,?,?,?,?,?,?,?,?)");
} 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;
return -1*e.getErrorCode();
}
return 1;
}
int ControladorDades::insertaServei(int numServei, int dia, int mes, int any, int hora, int minut, int idSoci, int idTarifa){
try{
_pstmt->setInt(1,7);
_pstmt->setInt(2,7);
_pstmt->setInt(3,7);
_pstmt->setInt(4,7);
_pstmt->setInt(5,7);
_pstmt->setInt(6,7);
_pstmt->setInt(7,7);
_pstmt->setInt(8,7);
_pstmt->execute();
} 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;
return -1*e.getErrorCode();
}
return 1;
}
I tryed to load the prepared statement without (?) and it works perfect... i mean like this:
pstmt = _con->prepareStatement((string)"INSERT INTO Serveis (id, numServei, dia, mes, any, hora, minut, idSoci, idTarifa) VALUES (NULL,7,7,7,7,7,7,7,7)");
Investigating a bit i know that this error means:
Error: 2036 (CR_UNSUPPORTED_PARAM_TYPE)
Message: Using unsupported buffer type: %d (parameter: %d)
But i'm not english and i don't know what refers buffer type...
Please, help!
Imanol.