Subject: Best method to store date & Time with SQL 2000
Posted By: harini19 Post Date: 2/14/2006 11:52:12 PM
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,Nationality,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?

Go to topic 40052

Return to index page 369
Return to index page 368
Return to index page 367
Return to index page 366
Return to index page 365
Return to index page 364
Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360