如标题中所述,我可以连接到我的数据库,但是当我尝试插入表格时出现错误。尝试修复它2天,但无法弄清楚语法的错误。该表存在2列VARCHAR(20)。
继承我的代码和控制台中打印的错误:
#include "MainClass.h"
#include <stdlib.h>
#include <iostream>
#include <vector>
#include "User.h"
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace sql;
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sf::TcpSocket socket;
bool running;
void login(std::string, std::string, std::string);
void Register(std::string, std::string, std::string);
void logout(std::string);
int main(void) {
//DB Connection
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "******");
stmt = con->createStatement();
stmt->execute("USE login");
Register("roflcat", "badumz", "192.168.0.2");
login("roflcat", "badumz", "192.168.0.2");
return0;
}
void Register(std::string name, std::string pw, std::string ip) {
//HERE THE ERROR OCCURS:
stmt->execute(("INSERT INTO user(name,pass) VALUES(%s,%s)", name, pw));
}
控制台出错: 您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在&roflcat附近使用&#39; roflcat&#39;在第1行创建用户roflcat
感谢您的帮助!