≫www.cnblogs.comjoeblackzqqp4332945.html according to the tutorial above, I used the second ConnectorC ++ method. After configuring the boost path and mysql path, I modified the sample code: & quot; # include & quot; mysql_driver.h & quot; # include & quot; mysql_connection.h & quot; # include mysqlc ++ database
Http://www.cnblogs.com/joeblackzqq/p/4332945.html
According to the tutorial above, I used the second method of Connector C ++. After configuring the boost path and mysql path, I modified the sample code:
# Include
# Include
# Include
# Include
# 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 namespace std; using namespace SQL; int main () {SQL: mysql: MySQL_Driver * driver = 0; SQL: Connection * conn = 0; try {driver = SQL: mysql: get_mysql_driver_instance (); conn = driver-> conn Ect ("tcp: // localhost: 3306/tree", "root", "123"); cout <"connection successful" <endl ;} catch (...) {cout <"connection failed" <endl;} SQL: Statement * stat = conn-> createStatement (); stat-> execute ("set names 'gbk'"); ResultSet * res; res = stat-> executeQuery ("SELECT * FROM testuser "); while (res-> next () {cout <"Id:" <res-> getInt ("id") <endl; cout <"Name: "<res-> getString (" name ") <endl; // cout <" addh Ss: "<res-> getString (" address ") <endl;} if (conn! = 0) {delete conn;} system ("pause ");}
For this reason, I created a database tree and table testuser:
create database tree;use tree;create table testuser(id INT(4) PRIMARY KEY,name CHAR(25),address varchar(45));desc testuser;insert into testuser values(1,'Tom','China Beijing'),(2,'Amy','America NewYork');select*from testuser;
After all the preparations are completed, start to execute:
Question: