使用Hibernate插入oracle Date类型的例子
2010-03-17 16:52
579 查看
package test;
import java.text.SimpleDateFormat;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;
import po.Stu;
public class Insert1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Configuration cf = new Configuration().configure();
SessionFactory sf = cf.buildSessionFactory();
Session session = sf.openSession();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String aa = "1999-12-22";
java.util.Date timeDate = null;
try {
timeDate = sdf.parse(aa);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}// util类型
java.sql.Date dateTime = new java.sql.Date(timeDate.getTime());// sql类型
Stu stu = new Stu("00000", "张三", "男", dateTime, "山东", "111");
Transaction t = session.beginTransaction();
try {
session.save(stu);
t.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
t.rollback();
session.close();
}
}
}
import java.text.SimpleDateFormat;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;
import po.Stu;
public class Insert1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Configuration cf = new Configuration().configure();
SessionFactory sf = cf.buildSessionFactory();
Session session = sf.openSession();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String aa = "1999-12-22";
java.util.Date timeDate = null;
try {
timeDate = sdf.parse(aa);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}// util类型
java.sql.Date dateTime = new java.sql.Date(timeDate.getTime());// sql类型
Stu stu = new Stu("00000", "张三", "男", dateTime, "山东", "111");
Transaction t = session.beginTransaction();
try {
session.save(stu);
t.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
t.rollback();
session.close();
}
}
}
相关文章推荐
- 使用Hibernate插入oracle Date类型的例子
- 使用Hibernate如何在Oracle中插入Date类型的数据
- Oracle Date类型字段使用Hibernate插入后没有时分秒的解决
- 使用hibernate想oracle插入date时,被截断
- Oracle中使用SQL插入语句对类型为Timestamp和Date的字段赋值
- 使用hibernate想oracle插入date时,被截断
- 在oracle 数据库中插入 时间类型的值,使用 to_date 函数
- 解决hibernate中使用new Date() 造成oracle date类型时分秒精准度丢失
- Hibernate使用自定义类型UserType映射Oracle的Date类型
- oracle 中插入date类型字段
- oracle的timestamp类型使用 插入
- oracle中使用sql语句将date日期7月21日2017类型转换为7/21/2017
- oracle的timestamp类型使用 插入
- ORACLE中date类型的使用
- 使用hibernate和mysql生成数据表时,类型为string的属性对应的数据列不能插入汉字
- 使用hibernate插入数据的例子
- hibernate对象映射Date数据类型和input datetime使用注意事项
- 向Oracle中插入date数据类型
- 关于Oracle字段类型Date使用mybatis generator自动生成工具出现的查询日期只精确到年月日问题
- oracle学习之路---新增列的数据插入与Date数据类型