1 java 类型, hibernate 类型 sql
java .lang.String string varchar
java.lang.String text Text
int int INT
char character char(1)
boolean boolean bit
byte[] binary blob
java.sql.Date date Date
java.sql.Timestamp timestamp Timestamp (载数据库中如果插入为null,数据库系统自动插入为当前值)
2 表述层--》业务逻辑层-》hibernate-》database
3
Configuration config=new Configuration();
config.add(Customer.class);
sessionFactory=conf.buildSessionFactory();
Session session=sessionFactory.openSession();
Transaction tx;
try{
tx=session.beginTransaction();
tx.commit();
}catch(Exception e){
if(tx!=null){
tx.rollback();
}
}finally{
session.close();
}
4 数据库存取blob 对象
1
InputStream in=this.getClass().getResourceAsStream("photo.gif");
byte[] buffer=new byte[in.available()]'
in.read(buffer);
customer.setImage(buffer);
2 byte[] buffer=customer.get.getImage();
File OutputStream fout=new fileOutStream("photo.gif");
fout.write(buffer);
fout.close();