Hi Dario,
UCanAccess supports the Access date formats and the # delimiter, so your sql statement is wrong.
You have to replace it with this:
UPDATE Trainers SET active=0, endAssignment=#2015-01-04# WHERE idTrainer=24
Cheers Marco
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So what I'm trying to is to get the user to input a date using Jdatechooser in eclipse, I then need to input this selected date in my database. I keep getting the error of invalid date time format.
This is my code :
try {
Connectionconn=DriverManager.getConnection("jdbc:ucanaccess://E:\\testing.accdb");Stringsql="insert into Homework (Description,Subject_ID,Name,Due_Date) values (?,?,?,?) ";PreparedStatementpst=conn.prepareStatement(sql);pst.setString(1,textFieldDes.getText());pst.setString(2,textFieldID.getText());pst.setString(3,textFieldName.getText());SimpleDateFormatsdf=newSimpleDateFormat("MM-dd-yyyy h:mm:ss aa");Stringdate=sdf.format(dateChooser.getDate());//java.util.DatetheDate=sdf.parse();//pst.setTimestamp(4,newjava.sql.Timestamp(theDate.getTime()));pst.setString(4,date);pst.executeUpdate();JOptionPane.showMessageDialog(null,"Data Saved");pst.close();}catch(Exceptione){e.printStackTrace();}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Good day and Happy new Year.
In order to deactivate the trainer in my program, is executed this code (in JAVA)
But it goes in Exception
net.ucanaccess.jdbc.UcanaccessSQLException: data exception: invalid datetime format
The query executed is this:
UPDATE Trainers SET active=0, endAssignment='2015-01-04' WHERE idTrainer=24
Maybe UCanAccess does not support "java.sql.Date"?
Can I use only java.util.Date?
Thank you.
Dario.
Last edit: Dario Ferrante 2015-01-05
Hi Dario,
UCanAccess supports the Access date formats and the # delimiter, so your sql statement is wrong.
You have to replace it with this:
UPDATE Trainers SET active=0, endAssignment=#2015-01-04# WHERE idTrainer=24
Cheers Marco
I will try and let you know.
Thank you.
Dario.
Perfect, I tried and the system is working correctly.
Thanks Marco.
Greetings.
Hi,
In my class i am declaring date like these
pre_date="2017-04-01 7:06:27 AM" .
output is : '#2017-04-01 7:06 AM#'
and it showing
But it goes in Exception
net.ucanaccess.jdbc.UcanaccessSQLException: data exception: invalid datetime format
can any one give me solution for these.
Sorry, but I do not understand what you are asking. Please provide a Minimal, Complete, and Verifiable Example that clearly illustrates the problem you are having.
k i will give clear explanation thank you for your reply
Actually, I want to get the date formate below mention code:
String pre_date="2017-04-01 7:06:27 AM";
// String SCHOOL_CODE="DC-EMP";
// System.out.println(pre_date+"//"+SCHOOL_CODE);
StringTokenizer st = new StringTokenizer(pre_date, " ");
String predate = st.nextToken();
String pretime = st.nextToken();
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
// Connection conn = DriverManager.getConnection("jdbc:ucanaccess://C:Program Files/eTimeTrackLite1.accdb;","","");
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://D:/Program Files/eSSL/eTimeTrackLite/eTimeTrackLite1.accdb;","","");
output: Error:: net.ucanaccess.jdbc.UcanaccessSQLException: data exception: invalid datetime format.
Canu u give me solution for this.
You are making things much more complicated than they need to be. You can parse the date/time string with
SimpleDateFormat
and then use a
PreparedStatement
to run the queryThat way you don't have to worry about creating a specific format for the query parameter.
if u dont mine can i send entire code to u to rectify problem
So what I'm trying to is to get the user to input a date using Jdatechooser in eclipse, I then need to input this selected date in my database. I keep getting the error of invalid date time format.
This is my code :
try {
Answered on Stack Overflow here.