因此,我能够使用命令提示符成功地在 Visual C++ 中构建程序。这是一个从数据库读取然后根据一些变量写入数据库的简单程序。所以我决定让它更花哨并添加一个按钮。我像以前一样将所有内容链接起来,发布了没有 cout 和 cin 的相同代码,但我收到了这段代码
1>stdafx.obj : 错误 LNK2028: 未解析的令牌 (0A00000D) "public: __clrcall sql::SQLString::~SQLString(void)" (??1SQLString@sql@@$$FQAM@XZ) 在函数 "public:虚拟__clrcall sql::mysql::MySQL_Savepoint::~MySQL_Savepoint(void)" (??1MySQL_Savepoint@mysql@sql@@$$FUAM@XZ)
1>新测试mysql.obj:错误LNK2028:未解析的令牌(0A00001E)“公共:__clrcall sql::SQLString::~SQLString(void)”(??1SQLString@sql@@$$FQAM@XZ)在函数中引用“私人: void __clrcall newtestmysql::Form1::mysqltest(void)" (?mysqltest@Form1@newtestmysql@@$$FA$AAMXXZ)
1>stdafx.obj : 错误 LNK2001: 无法解析的外部符号 "public: __clrcall sql::SQLString::~SQLString(void)" (??1SQLString@sql@@$$FQAM@XZ)
1>新测试mysql.obj:错误LNK2019:未解析的外部符号“public:__clrcall sql::SQLString::SQLString(char const * const)”(??0SQLString@sql@@$$FQAM@QBD@Z) 中引用函数“私有:void __clrcall newtestmysql::Form1::mysqltest(void)”(?mysqltest@Form1@newtestmysql@@$$FA$AAMXXZ)
错误发生了大约 3 次
这是代码
void mysqltest(){
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "");
/* Connect to the MySQL test database */
con->setSchema("awesome");
stmt = con->createStatement();
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test(id INT)");
delete stmt;
/* '?' is the supported placeholder syntax */
pstmt = con->prepareStatement("INSERT INTO test(id) VALUES (?)");
for (int i = 1; i <= 10; i++) {
pstmt->setInt(1, i);
pstmt->executeUpdate();
}
delete pstmt;
/* Select in ascending order */
pstmt = con->prepareStatement("SELECT id FROM test ORDER BY id ASC");
res = pstmt->executeQuery();
/* Fetch in reverse = descending order! */
res->afterLast();
while (res->previous())
delete res;
delete pstmt;
delete con;
}
catch (sql::SQLException &e) {
}
}
任何和所有的帮助表示赞赏。