Mysql Connector C++ statement values question I just want to know, if a value, like an int for example, is actually converted into a string before being sent as part of the command.

pstmt = con-&gt;prepareStatement("INSERT INTO test(id) VALUES (?)");


Usually, the ? is replaced with:

pstmt-&gt;setInt(1,155);


What I'm curious about is: could I simply make the command:

pstmt = con-&gt;prepareStatement("INSERT INTO test(id) VALUES (155)");


And execute it? Would it be the same as setInt? (basically that would mean that the int value is converted to a string before being set as part of the command)
While both methods are perfectly legitimate, there is one major difference.


When you prepare a SQL statement, you precompile it and substitute values using setInt().
When you hardcode the actually values, you have to precompile the SQL every time.


Please note when it comes to Com_stmt_prepare and Com_stmt_execute


only Com_stmt_execute would increment
both increment in the MySQL Server Status when you hardcode


Prepared statements are only to your advantage if you maintain persistent or pooled connections. This is the case because certain data structures must be allocated on the server-side. If you connect and disconnect all the time, you have to construct and destroy the prepared statement along with a host of other connection-based resources (See my old post How costly is opening and closing of a DB connection?)