개발/Database

[SQL 오류] -SQLException

poongho 2018. 6. 11. 10:27
반응형
{"error":1,"message":"qQLExceptionjava.sql.SQLSyntaxErrorException: Unknown column '1' in 'where clause'"}


SQL 구문에 오류가 있다는 뜻


사례) 


ResultSet resultSet = statement.executeQuery("SELECT * FROM goods WHERE id = `" + goodsid +"`"); 


에서 ' 를 `로 잘못 쓴 경우


ResultSet resultSet = statement.executeQuery("SELECT * FROM goods WHERE id = '" + goodsid +"'"); 


로 변경 시, 정상 작동함




cf.  SQL 구문에서는 ' 를 쓰고

     prepareStatement 에서는 ` 를 쓴다.


예시)  pstmt = connection.prepareStatement("INSERT INTO `test`.`Goods` "

                 + "(`title`, `address`, `area`, `deposit`, `month`, `floor`, `maintain`, `type`, `type2`, `elevator`, `parking`, `image_id`) "

                 + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");