我正在尝试连接到我的远程数据库mysql服务器。我在Windows10EnterpriseMysql连接器c1.1.9的代码块17.12IDE中使用c。
以下是我的构建选项。
我使用以下代码测试连接:
# include <iostream>
# include <cstdlib>
# include <string>
using namespace std;
# include "cppconn/driver.h"
# include "cppconn/exception.h"
# include "cppconn/resultset.h"
# include "cppconn/statement.h"
# pragma comment(lib, "mysqlcppconn.lib")
const string server = "tcp://127.0.0.1:3310";
const string username = "user";
const string password = "password";
int main()
{
sql::Driver *driver;
sql::Connection *dbConn;
object
sql::Statement *stmt;
sql::ResultSet *res;
try
{
driver = get_driver_instance();
}
catch (sql::SQLException e)
{
cout << "Could not get a database driver. Error message: " <<
e.what() << endl;
system("pause");
exit(1);
}
// Try to connect to the DBMS server
try
{
dbConn = driver->connect(server, username, password);
}
catch (sql::SQLException e)
{
cout << "Could not connect to database. Error message: " << e.what()
<< endl;
system("pause");
exit(1);
}
stmt = dbConn->createStatement();
try
{
stmt->execute("USE teste");
res = stmt->executeQuery("show tables");
}
catch (sql::SQLException e)
{
cout << "SQL error. Error message: " << e.what() << endl;
system("pause");
exit(1);
}
while (res->next())
{
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete dbConn;
system("pause");
return 0;
}
我得到以下错误。
如何修复?
更新
暂无答案!
目前还没有任何答案,快来回答吧!