Próbowałem wstawić identyfikatora użytkownika (int) i nazwę użytkownika (ciąg) przy użyciu PreparedStatement użyciu JDBC stosując następujące metody:MySQLSyntaxErrorException gdy próbuje wykonać PreparedStatement
public boolean saveUser(int userId, String userName){
boolean saveStatus = false;
try {
connection.setAutoCommit(true);
String sql = "insert into testtable values(?,?)";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setInt(1, userId);
statement.setString(2, userName);
saveStatus = statement.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
}finally{
Connector.closeConnections();
}
return saveStatus;
}
otrzymuję następujący StackTrace:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near '?,?)' at line 1
Co robię źle?
To nie ma sensu, ponieważ błąd "użyj w pobliżu"? Gdzie id =? "nie jive z instrukcją SQL. – OldProgrammer
Pokaż nam instrukcję tworzenia tabeli dla testtable –
utworzyć tabelę testową testową (id liczba całkowita, nazwa char (50)); – bhattedon