#includeusing namespace mysqlx; // Create a prepared statement Session sess("localhost", 33060, "user", "password"); Schema db = sess.getSchema("mydb"); Table mytable = db.getTable("mytable"); PreparedStatement stmt = mytable.prepareStatement("INSERT INTO mytable(col1, col2) VALUES(?, ?)"); // Set the value of the first parameter as 1234 uint16_t val1 = 1234; stmt.setUInt16(1, val1); // Set the value of the second parameter as 5678 uint16_t val2 = 5678; stmt.setUInt16(2, val2); // Execute the prepared statement stmt.execute();
#includeThe package library used for the PreparedStatement setUInt16 function in C++ varies depending on the database management system being used. For example, for MySQL databases, the C++ MySQL Connector/C++ library is commonly used, while for SQLite databases, the C++ SQLite3 library is commonly used.// Create a prepared statement sqlite3* db; sqlite3_prepare_v2(db, "SELECT * FROM mytable WHERE col1 < ?", -1, &stmt, nullptr); // Set the value of the parameter as 1000 uint16_t val = 1000; sqlite3_bind_int(stmt, 1, val); // Execute the prepared statement sqlite3_step(stmt);