wood burning stoves 2.0*
The moose likes JDBC and the fly likes Java + MS Access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java + MS Access" Watch "Java + MS Access" New topic
Author

Java + MS Access

Cormac De Barra
Greenhorn

Joined: Mar 13, 2006
Posts: 1
I'm have a database with two fields Date(Date/Time) and amount(text) and I want to retrieve the Date With the following code.


Connection connectionObject;
connectionObject = DriverManager.getConnection(URL,username,password);
StatementObject = connectionObject.createStatement();

String sqlQuery = "SELECT [Date] FROM Account;";

ResultSet statementResult = statementObject.executeQuery(sqlQuery);
while(statementResult.next())
{
DateFormat df = DateFormat.getDateInstance();
java.sql.Date d = statementResult.getDate(1);
String formattedDate = df.format(d);
}

but I get this error:

Problem with nullsent to jdbc dbc:shop.
Problem is : [Microsoft][ODBC Microsoft Access Driver]Invalid character value for cast specification on column number 1 (Date)

Can anyone tell me what the problem is and how to fix it.

Thx
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
instead of java.sql.Date try java.sql.TimeStamp.

The java.sql.Date supports only date not Date + time.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
As I told you already on the Sun JDBC forum using Date for the name of a column is a really bad idea. Don't use SQL reserved words (including data types) for column names.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java + MS Access