| Author |
java.sql.Date problem
|
oghenekaro EFEKODO
Ranch Hand
Joined: Oct 10, 2005
Posts: 56
|
|
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 dbc: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));
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
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?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
oghenekaro EFEKODO
Ranch Hand
Joined: Oct 10, 2005
Posts: 56
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
|
One other thing, why are you using the JDBC-ODBC bridge? Is Access your database?
|
 |
oghenekaro EFEKODO
Ranch Hand
Joined: Oct 10, 2005
Posts: 56
|
|
|
yes,my database is access
|
 |
 |
|
|
subject: java.sql.Date problem
|
|
|