• Post Reply Bookmark Topic Watch Topic
  • New Topic

Database Insert With java.util.Date

 
david k
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem with a database insert. Here is the code
for the function:
public void executeEFormInsertTest(String d, String dd,
String ddd, String user, String day1, String code1, String hours1) {
try {
conn = DriverManager.getConnection(DB_DSN,DB_USER,DB_PWD);
pstmt = conn.prepareStatement(insertEFormTest);

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
java.util.Date date1 = sdf.parse(d);
java.util.Date date2 = sdf.parse(dd);
java.util.Date date3 = sdf.parse(ddd);

pstmt.clearParameters();
pstmt.setDate(1, date1);
pstmt.setDate(2, date2);
pstmt.setDate(3, date3);
pstmt.setString(4, user);
pstmt.setString(5, day1);
pstmt.setString(6, code1);
pstmt.setString(7, hours1);
pstmt.executeUpdate();
//pstmt.close();
}
catch(SQLException se) {
System.out.println(se.toString());
}
finally {
if(pstmt !=null) {
try {
pstmt.close();
conn.close();
} catch(Exception e) {
System.out.println("Error while closing db connection");
}
}
}
} // executeEFormInsertTest()
The compiler complains that the [ pstmt.setDate(1,date1); etc..]
calls are not able to be resolved. This is strange to me?? The dates are passed to the function as String objects and I convert them to a java.util.Date using the SimpleDateFormat class.. Any suggestions??
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two questions, what database and drivers are you using, and what is the specific error being returned?
Dave
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He was getting a compiler error because he's passing a java.util.Date to a method that requires a java.sql.Date!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!