I am using MySQL 5.5 and I am inserting datetime into my table through Java, using the query:
INSERT INTO player_sale(transaction_id,player_id,game_id,game_type_id,ticket_nbr,mrp_amt,deduct_from_bonus,deduct_from_deposit,deduct_from_winning,good_cause_amt,vat_amt,taxable_sale,transaction_date,is_cancel) VALUES(48160,1001501,1,2,0,1.0,0.0,1.0,0.0,0.0,0.0,1.0,'2015-07-09 18:45:01','N');
but the entry inserted is 0000-00-00 00:00:00 in the transaction_date column.
In addition to it, when I am executing the above query, through the query browser interface of MySQL, the correct datetime is inserted . The datatype of transacion_date is datetime.
I have dug out a lot of web, but I couldn't find the answer regarding the same.
I used the following java code :
try{
Timestamp transactionDate = new Timestamp(Calendar.getInstance().getTimeInMillis());
String query="INSERT INTO player_sale(transaction_id,player_id,game_id,game_type_id,ticket_nbr,mrp_amt,deduct_from_bonus,
deduct_from_deposit,deduct_from_winning,good_cause_amt,vat_amt,taxable_sale,transaction_date,is_cancel)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
PreparedStatement pt = con.prepareStatement(query);
pt.setLong(1, 1);
pt.setLong(2, 110021);
pt.setInt(3, 1);
pt.setInt(4, 1);
pt.setLong(5, 12345678);
pt.setDouble(6, 10.00);
pt.setDouble(7, 20.00);
pt.setDouble(8,30.00);
pt.setDouble(9, 40.00);
pt.setDouble(10, 10.00);
pt.setDouble(11, 2.00);
pt.setDouble(12, 1.00);
pt.setTimestamp(13, transactionDate);
pt.setString(14, "N");
pstmt.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}
Aucun commentaire:
Enregistrer un commentaire