MySQL Query executes but throws exception

后端 未结 3 577

My code:

try {
    sql::Driver *driver;
    sql::Connection *con;
    sql::Statement *stmt;

    /* Create a connection */
    driver = get_driver_instance()         


        
3条回答
  •  日久生厌
    2021-01-11 19:58

    You are using executeQuery, which supposed to return sql::ResultSet object, and you are quering "CREATE USER" which returns true or false.

    There is an execute method for such cases. So...

    stmt = con->createStatement();
    stmt->execute("CREATE USER 'user22'");
    

    won't throw an error.

    Yeah, i know that the post is 2 years old, but if someone bumps in to the same problem in future could be of use to them.

提交回复
热议问题