Ing between date type in Hibernate and date in Oracle

Source: Internet
Author: User

The first time I used hibernate for persistence layer today, I had to admit that it was really easy to use and ignored a lot of things I had to worry about.

For example, if the connection is enabled and the SQL statement is disabledCodeVarious exception method calls, etc.

However, this kind of security is also caused by the uncontrolled underlying SQL statements.

Then, I used to process the date object declarations in the string type and then passed the SQL statement to_date (S, 'yyyy-mm-dd ')

What about now?

An exception occurred while changing the type.

Org. hibernate. Exception. dataexception: cocould not execute JDBC batch update

Caused by: Java. SQL. batchupdateexception: ORA-01861: text does not match the Format String

 

Obviously, the string cannot be directly inserted into the Date Field of the database.

Sorry, 00.

If you don't have any ideas, you can immediately change the date type to modify the corresponding ing file.

However, the assignment is hard to understand.

 

For example

 

Suppose I want to specify the insert date

If you can't do anything, you can't handle it.

 

 
Date =NewDate ();

 

I asked my colleagues, because the guy used the date type all the time before using JDBC.

We know that we can use the simpledateformat class to format string dates.

After reading simpledateformat, there is a parse (string) method that returns the date object!

 

 
NewSimpledateformat ("yyyy-mm-dd"). parse ("2008-10-25 ");

 

The SAVE () operation is successfully inserted!

Next, read the database.

However, it is required to print the data displayed from January 1, 1990 to January 3, September.

 

 
NewSimpledateformat ("yyyy-mm-dd"). Format (E. getinvoice_date ());

 

Display Results: October 1, 1990-October 3, September

Note: simpledateformat format (Object O); strings cannot be formatted directly.

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.