Hi All I am new to this. I was trying to insert Two date fields to Mysql .PFB // DAO class method to add fields.All the fields are coming from jsp form.
public boolean addIssue(Connection conn, IssueDTO dto)throws ParseException{
String startDate=dto.getStartDate();
String endDate=dto.getStartDate();
System.out.println("the start date from dto--"+dto.getStartDate());
System.out.println("The end date from dto"+dto.getEndDate());
DateFormat format=new SimpleDateFormat("MM/dd/yyyy");
Date newStartDate=format.parse(startDate);
Date newEndDate=format.parse(endDate);
try{
String sql="INSERT INTO issue_description (issue,keyword,applicationName,objectName,teamName,startDate,endDate,resolution,priority) values (?,?,?,?,?,?,?,?,?)";
PreparedStatement statement=conn.prepareStatement(sql);
statement.setString(1, ""+dto.getIssue());
statement.setString(2, ""+dto.getKeyword());
statement.setString(3, ""+dto.getApplicationName());
statement.setString(4, ""+dto.getObjectName());
statement.setString(5, ""+dto.getTeamName());
statement.setString(6, ""+newStartDate);
statement.setString(7, ""+newEndDate);
statement.setString(8, ""+dto.getResolution());
statement.setString(9, ""+dto.getPriority());
statement.executeUpdate();
below is the error log:::first four lines are the value of dates coming from jsp checked at various stages. But while inserting in DB its changing to 'Wed Oct 14 00:00:00 IST 2015'. Please suggest whats happening here.
10/14/2015
10/14/2015
the start date fr om dto--10/14/2015
The end date from dto10/14/2015
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: 'Wed Oct 14 00:00:00 IST 2015' for column 'startDate' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2983)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at com.sm.dao.IssueDAO.addIssue(IssueDAO.java:65)
at com.controllers.AddIssueController.doPost(AddIssueController.java:72)