我想用java連接到mySQL數據庫。我似乎能夠連接,但無法使用stmt.executeUpdate上傳到數據庫。我想上傳令牌是一個字符串,但我得到這個在我的控制檯:將字符串上傳到mySQL |語法錯誤
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;
}
我不確定爲什麼它不起作用並想要將字符串上傳到數據庫。 預先感謝您。
查詢運行的是什麼? – tadman
'stmt.executeUpdate'應該傳遞一個SQL語句。你發送的'token'看起來像一些長代碼,而不是有效的SQL。你希望發生什麼樣的SQL更新? –