MySQL connector C + + (vc2010)

Source: Internet
Author: User
Tags mysql version

The past few days have been trying to connect MySQL C + +, tried the MySQL C API and MySQL connector C + + 2 methods (there is also a way to use ADO, but the master is lazy, or prefer to compare the method of direct point), but the MySQL C API Compiled through but not run, so replaced by MySQL connector C + + this way. Next I'll be documenting my process of configuring vc2010

  0x00 Environment

ide:vc2010

C + + library: Boost (use MySQL connector C + + to configure the Boost library first), MySQL connector C + + 1.1.5

Database: mysql5.6

0X01 installs the Boost library as well as MySQL connector C + +

Start by downloading the boost library and MySQL connector C + + (these 2 items will be available on the respective official web, no link is provided)

Install the Boost library, download the Boost-1.58.zip, After decompression run Bootstrap.bat, after the completion of the run will be more than B2.exe and Bjam.exe these 2 can run programs, here we just run Bjam.exe (this program will run longer, you can see a set of silver Soul said ^_^), After the end you can gross position files to the folder you need.

As for MySQL connector C + +, I directly download the. msi installation file, install it, the default directory is C:\Program Files\mysql\mysql connector C + + 1.1.5

Now that the required files are installed, the next step is to configure vc2010.

  0x02 Configuration vc2010

1. First create an empty project and add a CPP file.

2. Add a catalog for the current project

Locate the Configuration Options page:

First we need to confirm that your MySQL version and MySQL connector C + + version is 32-bit or 64-bit, if it is 64-bit, we need to set the VC2010 platform to 64-bit, otherwise the compilation will not pass.

Project-->properties Options page has pllatform this option, default to the first 32-bit created, click Configuration Manager modified to 64-bit

Project-->properties-->c/c++ Select the general additional Include directories add MySQL connector C + + include folder and boost The folder

        

Project-->properties-->linker Select additional Library directories add MySQL connector C + + Lib folder and boost Li BS folder

        

Project-->properties-->linker Select additional Dependencies in input to add mysqlcppconn.lib

        

At this point we have completed the vc2010 configuration

   0X03 Verification

The next step is to verify that the environment is configured successfully, and we can write the following test code (first make sure that MySQL has a test database)

#include <iostream>#include"Mysql_driver.h"#include"Mysql_connection.h"#include"Cppconn/driver.h"#include"cppconn/statement.h"#include"cppconn/prepared_statement.h"#include"cppconn/metadata.h"#include"Cppconn/exception.h"using namespacestd;using namespaceSQL;intMain () {Sql::mysql::mysql_driver*my_driver =0; Sql::connection*connect =0; Try//attempt to connect to the TestDB database{my_driver=sql::mysql::get_mysql_driver_instance (); Connect= My_driver->connect ("Tcp://localhost:3306/testdb","Root","12345678"); cout<<"Connect success!"<<Endl; }    Catch(Exception e)//Connection Failed{cout<<"Connect fail!"<<Endl; }    //Sample Data collectionsql::statement* stat = connect->createstatement (); Stat->execute ("set names ' GBK '"); ResultSet*Res; Res= Stat->executequery ("SELECT * from user");  while(res->Next ()) {cout<<"ID:"<< res->getstring ("ID") <<Endl; cout<<"NAME:"<< res->getstring ("name") <<Endl; }    if(Connect! =0)//Release Connection    {        DeleteConnect; } getchar ();}

  0x04 End

MySQL C API estimation is also a version issue, compile clearly can pass, however, there is no egg use. So there are really unresolved problems can try to change another method (technology is too slag, Ouduok)

MySQL connector C + + (vc2010)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.