• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
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));
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1. i used this and recieve exception message
...
2.also tried this in my code and recieve an exception.


What does the exception message say? Where is it being thrown from?
 
oghenekaro EFEKODO
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry i forgot.thanks for telling to include the kind of exception.
exception for
1. syntax error in INSERT INTO statement.
2.compile with -Xlint:deprecation
when i did,it tells me that java.util.Date(String s) is deprecated.so what i used to replace it.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


syntax error in INSERT INTO statement.


So, this error is telling you you SQL is invalid. If you read the whole error message it should tell you why.


2.compile with -Xlint:deprecation


This is not an error message, it is part of a compiler warning. So it is not waht is stopping your code from working it is just informing you that you have choosen to use code that is very out of date. If you look at the JavaDocs for DateFormat you will notice there are a number of methods that parse string representations of dates and return them as Date objects. Use one of them instead.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One other thing, why are you using the JDBC-ODBC bridge? Is Access your database?
 
oghenekaro EFEKODO
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes,my database is access
 
Trust God, but always tether your camel... to this tiny ad.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic