Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Handling Oracle TimeStamp from JPA

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I am using oracle 11g, JPA -Eclipse link implementation. The oracle has a table called currency

TABLE currency
Name Null? Type
----------------------------------------- -------- ----------------------------
CODE NOT NULL CHAR(3)
DESCRIPTION VARCHAR2(120)
CRT_ID VARCHAR2(10)
CRT_TIMESTAMP TIMESTAMP(6)

code + crt_timestamp is a composite primary key

Data in oracle
===========

COD DESCRIPTION CRT_ID CRT_TIMESTAMP
ind india system 05-AUG-12 01.47.02.250000 PM

Using JPA Named query, i am trying to retrieve the currency code with crt_timestamp in the query where clause.

The PO field for crt_timestamp is java.util.Date, i am unable to retrieve the result set since the the crt_timestamp format is not known.


The below code snippet i tried, but unable to retrieve the data

String dateFormat = "dd-MMM-yy HH.mm.ss.SSS aa"; //i see date format in oracle 11g
String date = "05-AUG-12 01.47.02.250000 PM";

DateFormat s = new SimpleDateFormat(dateFormat);
Date d = null;
try {
d = (Date)s.parse(date);
} catch (ParseException e) {
}

Timestamp ts = new Timestamp(d.getTime());

Currency resultBook = (Currency)em
.createQuery("select b from Currency b where crt_Timestamp="+ts)
.setMaxResults(1)
.getSingleResult();


Please could you shed some light on this and tell me if it will be done.

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the future please UseCodeTags.

You have not showed us your currency object containing your mappings. But it should look something like this:

 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The timestamp format in JPQL is, {ts'yyyy-mm-dd hh:mm:ss.nnnnnnnnn'}

But in general you should use a parameter,

See,
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#Parameters
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic