Monday, 12 August 2013

Insert Not working through Java code but works in sqlDeveloper

Insert Not working through Java code but works in sqlDeveloper

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);
Above is the code to I'm using to insert into Mysql DB. Right on top is
the query which I found after trying to debug which works well in
SQLDeveloper but gives the following exception.
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..

No comments:

Post a Comment