We have many tool to deal with database, as giant Hibernate , famous Spring JDBC template , Spring Jpa , there are too many that , en , I can't mention all .
at first we use JDBC , haha , just like something belove code, quit a lot code
Connection con= null;
PreparedStatement pStmt=null;
ResultSet rs = null;
try{
con = ods.getConnection();
String sql = "select * from admin";
pStmt=con.prepareStatement(sql);
rs=pStmt.executeQuery();
while(rs.next())
{ }
}
catch(Exception ex) {
try{
con.rollback();
}catch(SQLException sqlex){
sqlex.printStackTrace(System.out);
}
ex.printStackTrace();
}finally{
try{
rs.close();
pStmt.close();
con.close();
}catch(Exception e){e.printStackTrace();}
}
and then Spring JDBC template
String sql = "select * from admin";
jdbcTemplate.query(sql,new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
}
} );
Spring Jpa, this example require JDK1.5+
@Repository
@Transactional
public class ArticleColumnDaoImpl implements ArticleColumnDao {
@PersistenceContext
private EntityManager entityManager;
public ArticleColumn getByid(long id) {
return entityManager.find(ArticleColumn.class,id);
}
public List<ArticleColumn> getbylayer(long layer) {
return entityManager.createQuery("select a from ArticleColumn a where a.layer =:layer").setParameter("layer",layer).getResultList();
}
public void addArticlekind(ArticleColumn articlekind) {
entityManager.persist(articlekind);
}
public void deleteArticlekind(long id) {
ArticleColumn articlekind=entityManager.find(ArticleColumn.class,id);
entityManager.remove(articlekind);
}
public void mergeArticlekind(ArticleColumn articlekind) {
entityManager.merge(articlekind);
}
}
this Jpa is quite like Hibernate , but something easier to code.
分享到:
相关推荐
Get familiar with functional and non-functional ways to deal with optionals Make use of functional data structures such as semigroup, monoid, binary search tree, linked list, stack, and lazy list ...
Get familiar with functional and non-functional ways to deal with optionals Make use of functional data structures such as semigroup, monoid, binary search tree, linked list, stack, and lazy list ...
How can we use a class Foo in a header file without access to its definition? We can declare data members of type Foo* or Foo&. We can declare (but not define) functions with arguments, and/or ...
Fixed a minor bug with the boundary.- Change the generator of the message id.- Added the field MessageId and InReplyTo to the TSakMsg component.- Added the field In-Reply-To that is added to the ...
3.4 User Data Manager (Dealing with Player Stats Such as Health, Lives, etc.)....37 3.4.1 Script Breakdown..........................................39 4. Recipes: Common Components 41 4.1 Introduction...
The Google API Client Library enables you to work with Google APIs such as Google+, Drive, or YouTube on your server. These client libraries are officially supported by Google. However, the libraries...
compared with field measurements to evaluate accuracies and determine how water surface roughness and point density affect LiDAR measurements. Results show that LiDAR derived water surface slopes were...
"With a large C++ code base, we rely on ACE to enable a cross-platform client-server framework for data quality and data integration. ACE has improved our design and smoothed over OS idiosyncrasies ...
Output buffering is a mechanism for controlling how much output data ; (excluding headers and cookies) PHP should keep internally before pushing that ; data to the client. If your application's ...
* And Optimizing The Base Code, Making It More Flexible! * If You've Found This Code Useful, Please Let Me Know. * Visit My Site At nehe.gamedev.net */ #include <stdio.h>> #include <windows.h> ...
inflating: zuitu/static/img/faq-how-it-works1.gif inflating: zuitu/static/img/faq-how-it-works2.gif inflating: zuitu/static/img/faq-how-it-works3.gif inflating: zuitu/static/img/how-it-works1.gif ...