eclipse - How to insert a date in a Date Type Column in HSQLDB Table using Hibernate? -
eclipse - How to insert a date in a Date Type Column in HSQLDB Table using Hibernate? -
i'm trying insert date type entry in column of table in hsqldb. issue i'm using hibernate so, can please help me how that?
the table follows:
create table test( workingdate date not null )
the bean file follows:
import java.util.date; public class test { private date workingdate; public date getworkingdate() { homecoming workingdate; } public void setworkingdate(date workingdate) { this.workingdate = workingdate; } @override public string tostring() { homecoming "test [workingdate=" + workingdate + "]"; } }
the xml mapping follows:
<?xml version="1.0"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="bean.hibpackage.test" table="test"> <property name="workingdate" column="workingdate" type="date" /> </class> </hibernate-mapping>
now testing scenario is:
import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.transaction; import org.hibernate.cfg.configuration; import bean.hibpackage.test; public class testhibernate2 { /** * @param args * @throws parseexception */ public static void main(string[] args) { // todo auto-generated method stub test test = new test(); string date_s = "2015-02-22"; { //how format above given string date type //program work } test.setworkingdate(?); session ses = null; seek { sessionfactory sessions = null; sessions = new configuration().configure().buildsessionfactory(); ses = sessions.opensession(); transaction tran = ses.begintransaction(); ses.save(test); tran.commit(); } { ses.close(); } } }
you need parse date
string representation:
string date_s = "2015-02-22"; simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); test.setworkingdate(sdf.parse(date_s));
eclipse hibernate hsqldb
Comments
Post a Comment