Here, is a simple java programme were i m trying to insert data in the table user_summary. But, the error i'm gettign is :
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression. at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source) at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source) at com.connection.JdbcConnection.main(JdbcConnection.java:43)
I don't hav any idea as to wat this error is. Pls. help me out in this.
The error you shown clearly mentions that type of columns and the data you are trying to send are not in sync. The possible situations could be, either your first column (USER_ID) is not a number or your second column(LOGIN_TIME) is not a String. I sense that your second column must be of type Date/Time, for which a String i.e cal.getTime().toString() won't work. Also, when you insert a Date using PreparedStatement, it cant't be java.util.Date but it has to be java.sql.Date
Hope it helps. Regards, Mahendra
Joined: Dec 12, 2007
Hi Mahendra, I tried using even a for USER_ID only. But, its still not working. in the table. user_id is a number for which i have given ps.setInt().
Should i use ps.setLong() or any other thnig?? Also, thanks for telling me abt. the Date.
I am able to only access data from the databade.. there is problem in inserting data in the database. I am using the local database. i.e. a .mdb file. Pls. tell me if any specific settings are required to be made.
What is LOGIN_TIME ? You are sending it a String, but is it a String, or a date, or what?
Joined: Oct 06, 2007
Originally posted by Bill Johnston: What is LOGIN_TIME ? You are sending it a String, but is it a String, or a date, or what?
or said another way... if you don't present your date string in the correct format or tell the data base that it is a date and the format of your date string you want to insert into the database date column... the database will not allow you to insert the row into the database because it appears (to the database) you are attempting to insert invalid data. [ December 13, 2007: Message edited by: Paul Campbell ]
Joined: Dec 12, 2007
Got It!!! Its working fine now. Thanks Guys for replying. There was a problem in date fromat.
I tried using java.sql.Date instead of java.util.Date and its working fine now.
Thanks once again to all.
Joined: Nov 17, 2005
You're welcome. If the DB column is a date - which you said it is - you might find it better to let the database form the date from the String. IOW ... in Oracle for example, I might have a date String in my Java program in this format '12152007', and I can insert it into the database date column like this: TO_DATE('12312006','MMDDYYYY'), and it will do the right thing. Something to check out if you do alot of date work.