如何使用mysql的连接器

How to use connector of mysql

本文关键字:连接器 mysql 何使用      更新时间:2023-10-16

我想为mysql数据库使用连接器。我正在关注这个页面

http://dev.mysql.com/tech-resources/articles/mysql-connector-cpp.html

但这似乎很难。还有其他教程吗。请告诉我。

示例代码的相关部分非常简单:

     Driver *driver;
     Connection *con;
     Statement *stmt;
     ResultSet *res;
    driver = get_driver_instance();
    /* create a database connection using the Driver */
    con = driver -> connect(url, user, password);
    /* alternate syntax using auto_ptr to create the db connection */
    //auto_ptr  con (driver -> connect(url, user, password));
    /* turn off the autocommit */
    con -> setAutoCommit(0);
    /* select appropriate database schema */
    con -> setSchema(database);

从那时起,你只需要像这样查询:

     stmt = con -> createStatement();
     res = stmt -> executeQuery ("SELECT * FROM City");