NÃO É POSSÍVEL!
Eu comparei a minha String com várias outras que achei pela internet, e nada.
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con;
con = DriverManager.getConnection("jdbc:mysql://localhost/sfashion", "root", "");
try {
String SQL = "DELETE FROM entregas WHERE nome=? and dataent=?";
PreparedStatement st = con.prepareStatement(SQL);
st.setString(1, cbbcli1.getSelectedItem().toString());
st.setString(2, cbbdata1.getSelectedItem().toString());
st.executeUpdate(SQL);
JOptionPane.showMessageDialog(null, "Registro removido.");
st.close();
con.close();
} catch (Exception s) {
System.out.println(s);
}
} catch (Exception s) {
System.out.println(s);
Se eu organizo minha String desse jeito:
String SQL = "DELETE FROM entregas WHERE nome=? and dataent=?";
PreparedStatement st = con.prepareStatement(SQL);
st.setString(1, cbbcli1.getSelectedItem().toString());
st.setString(2, cbbdata1.getSelectedItem().toString());
O mysql retorna: “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 ‘? and dataent=?’ at line 1”
E seu organizo minha String desse jeito:
String SQL = "DELETE FROM entregas WHERE nome="+cbbcli1.getSelectedItem().toString()+" and dataent="+cbbdata1.getSelectedItem().toString();
PreparedStatement st = con.prepareStatement(SQL);
st.executeUpdate(SQL);
O mysql retorna: “com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘Henrique’ in ‘where clause’”
(“Henrique” foi o valor que eu cadastrei no banco, na coluna name, para fazer testes).
Além disso, já testei usando execute() e executeUpdate() no preparedStatement, nenhum dos dois vai.
OBS: Eu passei um bom tempo estudando java, mas ainda tenho algumas dúvidas. Mas eu sempre pesquiso antes de criar um novo tópico aqui. 