• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Java + MS Access

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
author
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of java.sql.Date try java.sql.TimeStamp.

The java.sql.Date supports only date not Date + time.
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!