查询:
INSERT INTO STUDENT(FIRST_NAME, LAST_NAME, MIDDLE_NAME, SEX, DATE_OF_BIRTH, PLACE_OF_BIRTH, CLASS_ADMITTED, DATE_OF_ADMISSION)
VALUES('Sac','Gow','','M','1995-08-28','asd','2','2013-08-06')
代码:
MyConnection myConnection = new MyConnection();
connection = myConnection.getConnection();
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, student.getFirstName());
ps.setString(2, student.getLastName());
ps.setString(3, student.getMiddleName());
ps.setString(4, student.getSex());
ps.setDate(5, (Date) student.getDateOfBirth());
ps.setString(6, student.getPlaceOfBirth());
ps.setString(7, student.getClassAdmitted());
ps.setDate(8, (Date) student.getDateOfAdmission());
ps.execute(query);
上面是我用来插入Mysql DB的代码。 最重要的是我在尝试调试后发现的查询在SQLDeveloper中运行良好,但是给出了以下异常。
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..