I want to insert datetime into a MySql database using Java and a prepared statement:
Calendar cal = Calendar.getInstance(); PreparedStatement stmnt = db.PreparedStatement("INSERT INTO Run " + "(Time) VALUE (?) "); stmnt.setDate(1, new java.sql.Date(cal.getTime())); stmnt.executeQuery();
NOTE: there is currently an error - not finding line (java.sql.Date) 4 here
db is an instance of a wrapper class class that provides what I need from java.sql - it's just getting the prepared statement from my connection object here.
The time (column) is the date in my database, and I can only see the setDate and setTime methods, but I want to save both - also my code does not work anyway; -)
If someone could give me some pointers to insert a combined date time (current time would be a big help as my first goal) in the MySql database using the prepared expression, I would be very grateful.
thanks
source share