在开发新闻管理系统的时候,对象进行批量处理的时候,如果直接用hibernate的方法不管用,必须结合jdbc的批量处理.
速度也提高了.
public void saveNews(News news){
Transaction tran = this.session.beginTransaction();
Connection conn = session.connection();
try {
PreparedStatement stmt = conn.prepareStatement("insert into news(url,title,content)value(?,?,?)");
stmt.setString(1, news.getUrl());
stmt.setString(2, news.getTitle());
stmt.setString(3, news.getContent());
stmt.execute();
tran.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}