밑에와 이어서 질문을 올리는데
아래 소스에서 mysql connector 쪽에서 문법 에러를 내뱉습니다...
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 '?, ?, ?, ?, ?, ?, ?, ?, now())' at line 1
아무리 봐도 sql 쪽엔 문법적인 에러가 않보여서
수동적으로 저 sql 문에서 ? 를 bean 에 있는 내용을 직접넣어서 sql 서버쪽에서 써보니 아무문제 없이 됩니다..
일단 환경은
Tomcat 6.0.35 / jdk 1.7.0_01 / common-dbcp 구성 / mysql-connector 5.1.18 / mysql 5.0.77
sql = new StringBuilder("INSERT INTO italk_location")
.append("(userid, latitude, longitude, altitude, accuracy, speed, provider, locationType, locationTime) ")
.append("VALUES(?, ?, ?, ?, ?, ?, ?, ?, now());")
.toString();
LOG.debug(new StringBuilder("sql : ").append(sql));
LOG.debug(jsonData);
try {
conn = DBTool.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, bean.getUserId());
pstmt.setDouble(2, bean.getLatitude());
pstmt.setDouble(3, bean.getLongitude());
pstmt.setDouble(4, bean.getAltitude());
pstmt.setDouble(5, bean.getAccuracy());
pstmt.setDouble(6, bean.getSpeed());
pstmt.setString(7, bean.getProvider());
pstmt.setString(8, bean.getLocationType());
pstmt.execute(sql);
http://dev.mysql.com/doc/refman/5.0/en/insert.html
아무리봐도 제가 알고있는 문법이 틀리진 않았는데 혹시나 해서 문법 설명을 보니 update 처럼 set 으로도 할수 있길래
sql = new StringBuilder("INSERT INTO italk_location SET ")
.append("userid_s = ?, latitude = ?, longitude = ?, altitude = ?, accuracy = ?, ")
.append("speed = ?, provider = ?, locationType = ?, locationTime = now();")
.toString();
로 바꾸어서 해보니
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 '?, latitude = ?, longitude = ?, altitude = ?, accuracy = ?, speed = ?, provider ' at line 1
로 나와서
INSERT INTO italk_location SET userid_s = ?, latitude = ?, longitude = ?, altitude = ?, accuracy = ?, speed = ?, provider = ?, locationType = ?, locationTime = now();
이부분 쪽이 문제 인것같은데..
(원래 userid 필드 였다가 혹시나 userid 가 미리 되어있는 상수 인가 싶어서 userid_s 로 바꾸었습니다.)
어찌해야할지 난감합니다 ㅠㅠㅠ