Question

I want to do a prepared statement like this:

pstmt=conn->prepareStatement("UPDATE partidos SET i?=? WHERE ID=?");
pstmt->setInt(1,lazo);
pstmt->setString(2,texto[lazo]);
pstmt->setInt(3,var);
pstmt->execute();

"lazo" is a variable in a for loop, texto[lazo] is a variable and var is another int variable.

When I run this query, it throws an exception: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'i?=? WHERE ID=?' at line 1".

It seems that it doesn't replace the '?'.

I tried with stringstreams, but the problem didn't fix.

Thanks.

Was it helpful?

Solution

Finally I opted for this.

stringstream stmtvar;
stmtvar << "UPDATE PARTIDOS SET minuto" << lazo << "='" << texto[lazo] << "' WHERE ID=" << var;
stmt->executeUpdate(stmtvar.str());

It worked perfectly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top