Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Best way to store Date and Time in SQL 2000

These are the JFormatted Text Fields from where I get the data. By default I display Today's data and will be changed by user later.

l11= new JLabel("Passport Date Of Expiry");
t11 = new JFormattedTextField(new SimpleDateFormat("dd/MM/yyyy"));
t11.setValue(new Date());
l12= new JLabel("Time of Entry");
t12 = new JFormattedTextField(new SimpleDateFormat("KK:mm "));
t12.setValue(new Date());
l9= new JLabel("Visiting Pass: Date Of Issue");
t9 = new JFormattedTextField(new SimpleDateFormat("dd/MM/yyyy"));
t9.setValue(new Date());
l10= new JLabel("Visiting Pass:Date Of Expiry");
t10 = new JFormattedTextField(new SimpleDateFormat("dd/MM/yyyy"));
t10.setValue(new Date());

This is actually the insertion code:
int len;
String query,query1;
java.sql.PreparedStatement pstmt,pstmt1;
try
{
File file = new File(img);
FileInputStream fis = new FileInputStream(file);
len = (int)file.length();
query=("insert into visitor (Filename,length,photo,category,name,Address,TelephoneNo,PurposeOfVisit,VisitingOfficial,N ationality,PassportNo,PassportDateOfExpiry,tag) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)");
//Filename,length,photo,
pstmt = conn.prepareStatement(query);
pstmt.setString(1,file.getName());pstmt.setInt(2, len);
// Method used to insert a stream of bytes
pstmt.setBinaryStream(3, fis, len);
pstmt.setString(4,t1.getText());
pstmt.setString(5,t2.getText());
pstmt.setString(6,t3.getText());
int phoneno=Integer.parseInt(t4.getText());
pstmt.setInt(7,phoneno);
pstmt.setString(8,t5.getText());
pstmt.setString(9,t6.getText());
pstmt.setString(10,t7.getText());
pstmt.setString(11,t8.getText());
java.util.Date d1 = new SimpleDateFormat("dd/MM/yyyy").parse(t11.getText());
java.sql.Date sqlDate1=new java.sql.Date(d1.getTime());
System.out.println(sqlDate1);
pstmt.setDate(12,sqlDate1);
pstmt.setString(13,t12.getText());
pstmt.setString(14,t9.getText());
pstmt.setString(15,t10.getText());

pstmt.setInt(13, 1);
pstmt.executeUpdate();
}
When I compile, there is no error. When I execute, it gives an exception, "optional feature not implemented". I've tested that it is only the problem with Date and Time Fields. Individually, I've tested for image,integer and string. It is working fine. Which is the best way to do this?
[2440 byte] By [harini19] at [2007-11-11 8:00:51]