我想使用MySQL C++连接器连接到数据库。我已经添加了库和源代码正确编译所有必要的#include语句。我正在使用的代码如下:MySQL连接器C++ - 无效指针
#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
using namespace sql;
Driver *driver;
Connection *con;
driver = get_driver_instance();
con = driver -> connect("tcp://127.0.0.1:3306/test", "test", "test");
}
该代码是从示例中采取并且应该正常工作。我大大缩短了代码,因为它在错误发生的最后一个“驱动程序 - >连接”行。我的错误消息如下:
*** glibc detected *** /home/username/NetBeansProjects/mysql/dist/Release/GNU-Linux-x86/mysql:
free(): invalid pointer: 0x091dd468 ***
我在Linux Mint Lisa上,运行最新版本的MySQL并使用NetBeans 7.1作为IDE。如前所述,代码编译正确,并且在发生错误的最后一条连接线上。任何帮助或其他连接机制的建议将不胜感激。
UPDATE
这里是从哪里连接定义
class CPPCONN_PUBLIC_FUNC Driver
{
protected:
virtual ~Driver() {}
public:
// Attempts to make a database connection to the given URL.
virtual Connection * connect(const sql::SQLString& hostName, const sql::SQLString& userName, const sql::SQLString& password) = 0;
virtual Connection * connect(ConnectOptionsMap & options) = 0;
...
没有看到有......在我的愚见驱动程序类的代码...
看起来好像有些记忆已经free'd,然后尝试再次free'd,但失败,因为它不再分配写入。无法真正告诉你已发布的代码,你可以发布其余的代码吗?或者链接到示例代码? – TomP89 2012-04-13 22:03:40
这就是所有代码!我将使用驱动程序 - > connect函数从页面发布代码,但是直接来自MySQL Connector开发团队,所以我怀疑它会包含一个错误:/。 – 2012-04-13 22:06:36
'get_driver_instance'是你的代码还是连接器的一部分?如果它是你的,发布_that_。 – ildjarn 2012-04-13 22:15:53