wood burning stoves 2.0*
The moose likes JDBC and the fly likes java.sql.Date problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.Date problem" Watch "java.sql.Date problem" New topic
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("jdbcdbc: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));
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.Date problem
 
Similar Threads
java.sql.Date problem
date problem not in access but sql server
JDBC-ODBC
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Opti onal fature not implem
inserting a date field