Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <memory>
- #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->connect("tcp://localhost:3306/ip_store", "root", "");
- cout << "连接成功" << endl;
- }
- catch (...)
- {
- cout << "连接失败" << endl;
- }
- sql::Statement* stat = conn->createStatement();
- // stat->execute("set names 'gbk'");
- ResultSet *res;
- res = stat->executeQuery("SELECT * FROM t_ip limit 10");
- while (res->next())
- {
- cout << "ip_start" << res->getString("ip_start") << endl;
- cout << "ip_end:" << res->getString("ip_end") << endl;
- cout << "region:" << res->getString("region") << endl;
- }
- if (conn != 0)
- {
- delete conn;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement