我正在尝试使用java连接到我的mySQL数据库 . 我似乎能够连接但无法使用stmt.executeUpdate上传到数据库 . 我试图上传的令牌是一个字符串,但我在我的控制台中得到了这个:
1b7a19bb5d924bc5b13d53c7b2a47394已连接com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第1行'1b7a19bb5d924bc5b13d53c7b2a47394'附近使用正确的语法
这是我目前在我的主类中的代码:
String token = tokengenerator.generateQR(url, location);
tokens.add(token);
System.out.println(token);
try {
conn = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);
System.out.println("Connected");
Statement stmt = (Statement) conn.createStatement();
stmt.executeUpdate(token);
System.out.println("Uploaded");
}catch (SQLException e){
System.err.println(e);
}
这就是我创建令牌的方式
public static String generateQR(String url, String location) throws Exception {
String uuid = UUID.randomUUID().toString();
uuid = uuid.replaceAll("-", "");
String scan= url + uuid;
ByteArrayOutputStream out = QRCode.from(scan).to(ImageType.PNG).stream();
File f = new File (location);
FileOutputStream fos = new FileOutputStream(f);
fos.write(out.toByteArray());
fos.flush();
return uuid;
}
我不确定为什么它不起作用,并希望将字符串上传到数据库 . 先感谢您 .
1 回答
您的
generateQR
函数返回uuid
,这不是一个sql语句 . 此返回值最终为token
变量,稍后将尝试执行该变量 .