Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT a row with date fields

Status
Not open for further replies.

thekobbler

Programmer
Oct 30, 2002
113
GB
OK, this one should be easy (!)

I have a table:-

Code:
ARTICLE
---------------
title CHAR(256)
url   CHAR(256)
date  DATE

I can't seem to get PointBase to accept..

Code:
insert into ARTICLE (title,url,date) values ('an article title','article.pdf','2003-01-22')

I've tried various combinations, but usually get..

Code:
java.sql.SQLException: Illegal cast operation between type: CHARACTER and type: DATE.

returned. Any clues as to how to set a "DATE" field value
 
According to the ANSI sql standard a date literal is specified as

insert into ARTICLE (title,url,date) values ('an article title','article.pdf',date '2003-01-22')
 
IN the meantime; I did it this way.. which I think I prefer.

Code:
  String insertPrepStmt = "insert into ARTICLE (title,url,date) values (?,?,?)";
  java.sql.PreparedStatement prepStmt = conn.prepareStatement(insertPrepStmt);
  prepStmt.setString(1,title);
  prepStmt.setString(2,url);
  prepStmt.setDate(3,java.sql.Date(date.getTime()));
  prepStmt.execute();
  prepStmt.close();

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top