Explain several common ways of spring connecting to the database in detail

This article briefly explains several common methods of using spring to connect to the database:

The main test categories are:

The first is to use the drivermanagerdatasource configuration file provided by spring as follows:

The second: c3p0 data source.

You need to make the core jar package of c3p0. I use c3p0-0.9 1. Jar, relatively stable, recommended. Usually when downloading hibernate, you will bring one: I'm in hibernate-release-4.3 0. Found in the final \ lib \ optional \ c3p0 path.

The configuration file is as follows:

Third:

The jar package you need to download to connect to the database using Apache's DBCP plug-in: commons DBCP jar,commons-pool. jar,commons-collection. jar

The spring configuration file is as follows:

Fourth:

Using hibernate data source requires hibernate core jar package. The version of Hibernate 1 I use is hibernate-release-4.3 0.Final

At present, the three frameworks are popular. Spring usually partners with hibernate. The database connection method is written in the configuration file of hibernate, and spring manages the configuration file in hibernate

You can directly read the hibernate core configuration file. When using hibernate to connect to the database, you need to read hibernate cfg. XML configuration file and corresponding entity class,

Readers can refer to the following self configuration

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>