You should use some DAOFactory , this class is used to get connections. To display tables in a database, you must create DTO - Data Tranfer Objects representing entities. Therefore, if you have a User table, simply create UserDTO.java with attributes and getters and setters. And the class for communicating with the database is DAO - Data Access Object . Here you should only create SQL statutes and methods to retrieve data from your database. Well designed structure first . Then your code becomes cleaner, faster and more secure. I recommend you create your own ORM . So take a look and check out a few frames
EasyORM
double count = 0; TransDB trans = new TransDB() ; List<Trans> list = new ArrayList<Trans>(); list = trans.getAll(); for (Trans element : list) { count+= element.getData(); } ...
Hibernate
double count = 0; Session session = null; List<Trans> list = new ArrayList<Trans>(); list = HibernateUtil.getSessionFactory().openSession(); list = (List<Trans>) session .createQuery("from Trans").list(); for (Trans element : list) { count += element.getData().doubleValue(); } ...
and compare
Rating (in ms)
EasyORM: MySQL: init - 6344, avg - 4868 MS SQL: init - 8126, avg - 6752
Hibernate: MySQL: init - 27406, avg - 23728 MS SQL: init - 28605 (+ 250%), avg - 24912
So, your own ORM , actually created from an SQL script , has an order faster than Hibernate (up to 10) and why ? Insertion between layers, of course, cannot go to increase throughput. This is just one test, I have others. Therefore, for me, I recommend that you create your own ORM , there are also some disadvantages here, such as consuming time, for example, or using problematic DMS changes, but the advantages are as complete control over the generated commands, you can use functions specific to a specific DMS (ORDM , special teams, etc.). Therefore, I do not think that Hibernate is the best, actually not.