I have a question
What are the different ways to connect a Java application to the database?
I've seen that you can by means of connection pool and hibernate but what are the other forms and which is the best to be able to use it?
I have a question
What are the different ways to connect a Java application to the database?
I've seen that you can by means of connection pool and hibernate but what are the other forms and which is the best to be able to use it?
Well, there are several ways, one of them is effectively Hibernate , but this is just one of the existing frameworks or plugins to make the connection to the database. On the other hand you can also make a connection to the database directly and without the use of any framework using the DataSource class, here the documentation.
All frameworks require a JDBC (the database controller) to be able to handle the database connection. This driver changes depending on each provider (that means, for example, Oracle has its own JDBC named OJDBC , Postgresql has one of its own as well and so on).
I personally recommend Hibernate for its robustness and easy configuration, but if what you need is something lighter than just consulting the database, MyBatis is fine. Do not try to make the connection without any Framework unless your reasons are for learning, because it can be very cumbersome.
Access to the database is done through JDBC (Java Data Base connectivity).
JDBC is a specification (API) provided by Oracle (as JAVA) and implemented by each Specific Database ... you have Java API Classes and Interfaces in the JRE (Java Runtime Environment) and you have to have a JAR additional with the implementation, eg: Oracle DB, Postgres, MySQL, etc .. each BD has its own JAR.
Hibernate, is a way to access data but it works on JDBC ... it is an ORM engine (like Relationship-Object Mapping) that helps to build in a 'Rapida' way an application where one can persist Objects.
Connection Pool also works on JDBC and it is a Utilitarian Library that helps you to administer the connections of Database. Open, Close, Have a limit of available connections, free if someone has a busy connection for a long time etc. .
In Conclusion, Basically JDBC is the only official way to access Databases.