• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Database Insert With java.util.Date

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 28227
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic