• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

java.sql.Date problem

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
need help urgently,i have been trying to input a date value via JTextField which is the date of transaction and i have been experiencing alot of problem.please somebody show how to insert date into my database from a text field.below are the methods i have tried and didn't work.thanks in advance.

1. i used this and recieve exception message
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:sparkletransaction","","");


java.sql.Date date =java.sql.Date.valueOf(dateF.getText());

String insert="INSERT INTO personaltransaction(date,name,phone,addres,deposit,balance) VALUES(?,?,?,?,?,?)";
//insert=insert+;
stat=con.prepareStatement(insert);

stat.setDate(1,date);
stat.setString(2,fullName);
stat.setString(3,phoneF.getText());
stat.setString(4,addressF.getText());
stat.setString(5,ss);
stat.setString(6,bb);

stat.executeUpdate();
stat.close();
}
catch(Exception e){
System.out.println(e);
}
}
2.also tried this in my code and recieve an exception.
Date date= new Date();
SimpleDateFormat template = new SimpleDateFormat("dd-mm-yyyy");
Date enddate = new Date(datefield.getText());
java.sql.Date date = java.sql.Date.valueOf(template.format(enddate));
 
reply
    Bookmark Topic Watch Topic
  • New Topic