1
我正在使用mysql庫連接到我的數據庫(mysql)以在連接後檢索數據。檢查我的服務是否正常運行。mysql cpp連接器在連接時拋出UnknownException
以下是代碼,不會連接任務的一部分。這
// Specify our connection target and credentials
const string server = "tcp://127.0.0.1:3306";
const string username = "root";
const string password = "";// No password - thanks, WAMP Server!
// Try to get a driver to use to connect to our DBMS
try {
driver = get_driver_instance();
if(driver == NULL)
throw SQLException("Null driver instance returned.");
}
catch (SQLException e) {
cout << "Could not get a database driver. Error message: " << e.what() << endl;
return -3;
}
// 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.getSQLStateCStr() << " Error Code: " << e.getErrorCode() << endl;
cout << "Could not connect to database. Error: " << e.what() << endl;
return -1;
}
它編譯良好,但給出了一個未知異常未知的調試信息。像這樣的東西。請幫忙。
我試過這個解決方案沒有成功。你做了什麼來使它工作? – paulosuzart