• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3870
  • Last Modified:

How to insert a Timestamp in Oracle from Java?

Hi,
I have a Oracle table column as Timestamp(6).
I also have another column that is just Date.

Now my question is: How do I insert a record in this table using the Timestamp(6)...

What are optlions...of ..converting a date to Timestamp???

Do I convert my date to a Timestamp?
Can I just create a new Timestamp(6) --- How?

Let me know...

Thax....
_Esam.
0
_Esam
Asked:
_Esam
  • 5
  • 4
2 Solutions
 
CEHJCommented:
Timestamp ts = new Timestamp(new java.util.Date().getTime());
prepStatement.setTimestamp(1, ts);
0
 
Ryan ChongCommented:
Alternatively try directly include the SYSDATE in your insert statement, like:

...
SQLStr = "Insert into mytable (fld1, fld2, myTimeStamp) values (?, ?, SYSDATE) ";
...
0
 
_EsamAuthor Commented:
>Timestamp(6)

What does this imply? size 6?
What does size 6 for Timestamp mean? I am not clear about this... It's in oracle table..

Let me know..

Thax.
_Esam

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
CEHJCommented:
>>What does size 6 for Timestamp mean?

Where have you seen that? The code i posted will work
0
 
_EsamAuthor Commented:
Yes, I tried both examples that are given above, and they worked just fine.

Well, when I do a desc TABLE1;

The timestamp rows I get as:

ROW_UPDT_TMS        TIMESTAMPT(6) ???

What does this mean?

Thanks.
_Esam.
0
 
CEHJCommented:
Probably the size of the datatype - 6 bytes long
0
 
_EsamAuthor Commented:
That would make sense?

But that byte thing is  related to java - I didn't think it was somehow related to oracle Timestamp!!!!


Thanks.
_Esam
0
 
CEHJCommented:
bytes are related to everything ;-)
0
 
_EsamAuthor Commented:
That's absolutely right but in terms of declaring the Oracle Timestamp!!
I didn't know that...

Thanks.
_Esam...
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now