1

The database I am working with has the date format as

DD-MON-RR

This is the table:

CREATE TABLE dependent (
     Fname     varchar2(15) not null,
     bdate     date,
);

I am currently trying to insert into a database using JDBC with the code

String insert = "INSERT INTO DEPENDENT(Fname,bdate) VALUES(?,?)";
PreparedStatement p = z.conn.prepareStatement(insert);
p.setString(1, "Billy");
String formatIn = "DD-MMM-YY";
SimpleDateFormat sdfi = new SimpleDateFormat(formatIn);
java.util.Date inDate = sdfi.parse("29-AUG-10");
java.sql.Date sqlDate = new java.sql.Date(inDate.getTime());
p.setDate(2, sqldate);
p.executeUpdate();

I thought this would fit the format expected, however it keeps giving me java.sql.SQLException: Io exception: Size Data Unit (SDU) mismatch

I'm unsure how to fix this

nelac123
  • 91
  • 1
  • 6

1 Answers1

1

Believe it or not, it looks as though your error has to do with the pattern you are using with SimpleDateFormat. Change the following:

String formatIn = "DD-MMM-YY";
SimpleDateFormat sdfi = new SimpleDateFormat(formatIn);
java.util.Date inDate = sdfi.parse("29-AUG-10");

to this and the problem should go away:

String formatIn = "dd-MMM-yy";
SimpleDateFormat sdfi = new SimpleDateFormat(formatIn);
java.util.Date inDate = sdfi.parse("29-AUG-10");

The D and Y speciciers denote the day in year and week year, respectively, and are probably not what you intended to use (see here: Y returns 2012 while y returns 2011 in SimpleDateFormat).

Note that the rest of your JDBC code looks OK to me.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360