기본적으로 데이터베이스 테이블을 getSelectRow 값으로 업데이트하려고합니다. 보시다시피 질의는 정확한 데이터를 찾았지만 실제로 데이터베이스에 추가 할 때 큰 문제가 있습니다.
오류는 SQL 구문에 있지만 어디에서 잘못 될지 알 수 없습니다. 도와주세요.INSERT 문장에서 알 수없는 SQL 문제
이 쿼리는 실행되지만 테이블을 업데이트하지 않는 이유는 알 수 없습니다.
INSERT INTO customerdetails
FName = 'Tim'
AND SName = 'Cooley'
AND Address = '52 Buckminster Drive Dorridge Solihull West Mids'
AND Postcode = 'B93 8PG'
자바 코드 :
private void sendBtnMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int insertRow = newOrderTbl.getSelectedRow();
int col2 = 0;
String sql3 = "INSERT INTO customerdetails VALUES "
+ "FName = '" + newOrderTbl.getValueAt(insertRow, col2) +"'"
+ "AND SName = '" + newOrderTbl.getValueAt(insertRow, col2+1) +"'"
+ "AND Address = '" + newOrderTbl.getValueAt(insertRow, col2+2) +"'"
+ "AND Postcode = '" + newOrderTbl.getValueAt(insertRow, col2+3) +"'";
System.out.println(sql3);
try{
pst = conn.prepareStatement(sql3);
pst.executeUpdate(sql3);
JOptionPane.showMessageDialog(null, "Deleted");
CustomerTable();
}
catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
SQL 인젝션 취약점이 있습니다. – SLaks
나는 알고있다. 그러나 이것은 아무데도 출판되지 않을 개인 프로젝트이므로 중요하지 않다. 오류는 제발 도와주세요. –
'pst.executeUpdate (...)'의 반환 값은 무엇입니까? Javadoc에 따르면, "(1) SQL 데이터 조작 언어 (DML) 문에 대한 행 수 또는 (2) 아무것도 반환하지 않는 SQL 문에 대해 0"을 리턴합니다. – mthmulders