81,094
社区成员
发帖
与我相关
我的任务
分享
package com.tarring.pojo;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Date;
import java.util.List;
import org.hibernate.Transaction;
import com.tarring.hibernate.HibernateUtil;
public class Test {
public static void main(String[] args) {
Test test = new Test();
//消费者对象创建
Customer customer = new Customer("U00010", "tarringint");
ICustomerDAO dao = new CustomerDAO();
customer.setBirthday(Date.valueOf("1988-08-08"));
// 插入图片
InputStream in = test.getClass().getResourceAsStream("image.jpg");
try {
byte[] buffer = new byte[in.available()];
in.read(buffer);
customer.setImage(buffer);
} catch (IOException e) {
e.printStackTrace();
}
/**
* 保存记录
*/
// dao.save(customer);// insert into t24.customer (UserName, Birthday,
// Image, CustomerId) values (?, ?, ?, ?)
/**
* 删除指定的记录(根据ID)
*/
// dao.delete(customer);//delete from t24.customer where CustomerId=?
/**
* 查找指定的记录(根据ID值)
*/
// Customer cus = dao.findById("U00002");
// System.out.println(cus.getUserName());
Transaction ts = HibernateUtil.getSession().beginTransaction();
Customer customer1 = new Customer();
customer1.setUserName("updatedao");
customer1.setCustomerId("U00001");
dao.update(customer1);
ts.commit();
HibernateUtil.closeSession();
/**
* 查找所有的记录
*/
// List<Customer> customerList = dao.findAll();
// for (Customer customer2 : customerList) {
// System.out.println(customer2.getCustomerId() + " ======== "
// + customer2.getImage());
// }
}
}