4
4
4ex0V2012-08-27 17:28:08
MySQL
4ex0V, 2012-08-27 17:28:08

What does passing a parameter to where look like in C++/MySQL?

Hello!

I want to write a query to the database through the for construct.
Something like this:

for (int i = 0; i < 10; i+)
{
Object.ExecuteQuery("select ip, prefix from server where id = i");
}

Of course, this construction will not work. How to correctly pass the value of i to where?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivnik, 2012-08-27
@4ex0V

Look at the prepareStatement method:

  pstmt = con->prepareStatement("INSERT INTO test(id) VALUES (?)");
  for (int i = 1; i <= 10; i++) {
    pstmt->setInt(1, i);
    pstmt->executeUpdate();
  }
  delete pstmt;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question