Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 对于查询,我将在上面的帖子中更新。getString()调用有点棘手。@里奇·霍夫曼:你试过用数字索引代替字段名吗?在我的代码中,我使用的是字段索引而不是名称。我切换回sql::语句,但没有用。检索查询的整数结果没有问题,我将在上面的帖子中更新。getSt_C++_Mysql_Linux - Fatal编程技术网

C++ 对于查询,我将在上面的帖子中更新。getString()调用有点棘手。@里奇·霍夫曼:你试过用数字索引代替字段名吗?在我的代码中,我使用的是字段索引而不是名称。我切换回sql::语句,但没有用。检索查询的整数结果没有问题,我将在上面的帖子中更新。getSt

C++ 对于查询,我将在上面的帖子中更新。getString()调用有点棘手。@里奇·霍夫曼:你试过用数字索引代替字段名吗?在我的代码中,我使用的是字段索引而不是名称。我切换回sql::语句,但没有用。检索查询的整数结果没有问题,我将在上面的帖子中更新。getSt,c++,mysql,linux,C++,Mysql,Linux,对于查询,我将在上面的帖子中更新。getString()调用有点棘手。@里奇·霍夫曼:你试过用数字索引代替字段名吗?在我的代码中,我使用的是字段索引而不是名称。我切换回sql::语句,但没有用。检索查询的整数结果没有问题,我将在上面的帖子中更新。getString()调用有点棘手。@里奇·霍夫曼:你试过用数字索引代替字段名吗?在我的代码中,我使用的是字段索引而不是名称。 Starting MySQLTest Id: 1 Id: 2 Id: 3 Id: 10 Id: 222 Id: 333 My


对于查询,我将在上面的帖子中更新。getString()调用有点棘手。@里奇·霍夫曼:你试过用数字索引代替字段名吗?在我的代码中,我使用的是字段索引而不是名称。我切换回sql::语句,但没有用。检索查询的整数结果没有问题,我将在上面的帖子中更新。getString()调用有点棘手。@里奇·霍夫曼:你试过用数字索引代替字段名吗?在我的代码中,我使用的是字段索引而不是名称。
Starting MySQLTest 
Id: 1
Id: 2
Id: 3
Id: 10
Id: 222
Id: 333
MySQLTest Exiting...
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id    | int(11)  | YES  |     | NULL    |       | 
| name  | char(30) | YES  |     | NULL    |       | 
+-------+----------+------+-----+---------+-------+
2 rows in set (0.13 sec)
+------+--------+
| id   | name   |
+------+--------+
|    1 | FIRST  | 
|    2 | SECOND | 
|    3 | THIRD  | 
|   10 | JUMP   | 
|  222 | TEST   | 
|  333 | TEST3  | 
+------+--------+
Starting MySQLTest 
Id: 1
Name: FIRST
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>

#include <stdlib.h>

//MySQL connection headers

#include <cppconn/driver.h>
#include <cppconn/connection.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <cppconn/resultset.h>
#include <cppconn/metadata.h>
#include <cppconn/resultset_metadata.h>
#include <cppconn/exception.h>
#include <cppconn/warning.h>

using namespace std;

int main()
{
    cout << "Starting MySQLTest \n";
    try
    {
        sql::Driver *driver;
        sql::Connection *connection;
        sql::PreparedStatement *prepStatement;
        sql::ResultSet *result;

        //Attempt to create a connection
        driver = get_driver_instance();
        connection = driver->connect("HOST", "USER", "PASS");
        connection->setSchema("testdb");

        prepStatement = connection->prepareStatement("insert into testtable(id, name) values(333, 'TEST3')");
        prepStatement->execute();
        prepStatement = connection->prepareStatement("select * from testtable");
        result = prepStatement->executeQuery();

        while(result->next())
        {
            cout << "Id: " << result->getInt("id") << "\n";
                    //TERMINATE AFTER THE FOLLOWING LINE
            cout << "Name: " << result->getString("name") << "\n";
        }

        delete result;
        delete connection;
    }
    catch(sql::SQLException &e)
    {
cout << e.what() << "\n";
    }

    cout << "MySQLTest Exiting...";

    return 0;
}
       insert_visitor.begin(rid);
       rid.accept_visitor(insert_visitor);
       insert_visitor.end();
       std::string             insertion_sql_text;
       insertion_sql_text += insert_visitor.get_query();
       std::cout << "\n" << insertion_sql_text << std::endl;
       sql::Connection *       p_db_connection(get_db_connection());
       boost::scoped_ptr<sql::Statement>               sql_stmt(p_db_connection->createStatement());
       if (!sql_stmt)
       {
               break;
       }
       try
       {
               sql_stmt->execute(insertion_sql_text);
       }
       catch (sql::SQLException exception)
       {
               wxLogDebug("SQL Exception thrown for executing: \"%s\"",
                                       insertion_sql_text.c_str());
       }

       //-------------------------------------------------------------
       //      Retrieve the new value of the auto incremented ID field.
       //-------------------------------------------------------------
       int new_id = -1;
       boost::scoped_ptr<sql::ResultSet>               query_results(sql_stmt->executeQuery("SELECT LAST_INSERT_ID()"));
       query_results->next();
       new_id = query_results->getInt(1);
       rid.set_record_id(new_id);