【发布时间】:2011-12-25 09:07:43
【问题描述】:
我正在使用 mysql 库连接到我的数据库(mysql)以在连接后检索数据。检查我的服务是否正常运行。
以下是执行连接任务的代码部分..
// 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;
}
它编译得很好,但给出了一个带有未知调试信息的未知异常。像这样的东西。请帮忙。
【问题讨论】:
标签: c++ mysql exception database-connection