I am having an error, I'm not sure why number of select types did not match those for insert. I have Request entity, with 3 values. billing_cycle, start_date, & end_date. I tried adding 0 at insert but still doesn't work.
UPDATE: My date is in String. It should be Date type. I changed SELECT to VALUES. I got new error: Unparseable date: "Tue Jan 15 00:00:00 SGT 2013"
My insert method
@Override
@Transactional
public void insertRequest(Request request) {
try {
DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd" );
DateFormat inputFormat = new SimpleDateFormat("E MMM dd HH:mm:ss Z
yyyy");
Date sdate = outputFormat.parse(request.getStart_date()) ;
Date edate= outputFormat.parse(request.getEnd_date()) ;
String sqlQuery;
sqlQuery = "INSERT INTO Request "
+ "(billing_cycle, start_date, end_date) VALUES ("
+
+ request.getBilling_cycle() +", "
+ "'"+ sdate +"', "
+ "'"+ edate+"')";
Query query = entityManager.createQuery(sqlQuery);
query.executeUpdate();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
My values
{
"billing_cycle":"1",
"start_date":"Tue Jan 15 00:00:00 SGT 2013",
"end_date":"Thu Feb 14 00:00:00 SGT 2013"
}
My entity
@Entity
@Table(name="request")
public class Request {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="request_id")
private int request_id;
@Column(name="billing_cycle")
private int billing_cycle;
@Column(name="start_date", columnDefinition="Date")
private String start_date;
@Column(name="end_date", columnDefinition="Date")
private String end_date;
Error:
Unparseable date: "Tue Jan 15 00:00:00 SGT 2013"
at java.base/java.text.DateFormat.parse(DateFormat.java:395)
Aucun commentaire:
Enregistrer un commentaire