hibernate configuration and JDBC connection pool

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

 

This is the header file of hiberante.cfg.xml, in a fixed form, otherwise it cannot be parsed

----------------------------------------------------------------------------------------------------------------------------------

 </hibernate-configuration>

          </session-factory>

                  configuration information

      </session-factory>

</hibernate-configuration>

----------------------------------------------------------------------------------------------------------------------------------

JDBC Configuration Project

          Database username: <property name="connection.username">sa</property>

          Database password: <property name="connection.password">sa123!</property>

          Connection string: <property name="connection.url">jdbc:jtds:sqlserver://localhost:1433/tjp_db</property>

          驱动类:<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>

          Database dialect: <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

          Database name: <property name="myeclipse.connection.profile">tjp_db</property>

                              <property name="hibernate.session_factory_name">tjp_db</property>

----------------------------------------------------------------------------------------------------------------------------------

Regular placement

        

  <!-- Set the database name when the url does not specify a database -->
          <!--    <property name="default_catalog">orcl</property>-->
          <!--Output all SQL statements to the console-->
         <property name="hibernate.show_sql" >true</property>
         <!-- Prints prettier SQL in log and console. -->
        <property name="hibernate.format_sql">true</property>
         <!-- Configure automatic update table structure (only columns can be added, not deleted) -->
         <property name="hibernate.hbm2ddl.auto">none</property>
         <!-- Enable query cache -->
          <property name="hibernate.cache.use_query_cache">false</property>
        <!-JavaBean-like xml->
        <mapping resource="Path(Class.hbm.xml)" />
 

 

----------------------------------------------------------------------------------------------------------------------------------

JDBC connection pool

Configure data source in Tomcat

Location: conf/content.xml

 

<?xml version='1.0' encoding='utf-8'?>
<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
 <!--	<Resource name="BigMagnate"
       auth="Container"
       type="javax.sql.DataSource"  
      maxActive="100"  
      maxIdle="30"
      maxWait="10000"   
      username="root"   
      password="root"
      driverClassName="com.mysql.jdbc.Driver"  
     	url="jdbc:mysql://localhost:3306/mydb"/>
   -->
</Context>
 

 

connection pool

	/**
	 * Get database connection
	 *
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	public static Connection getConnection() throws ClassNotFoundException,
			SQLException {
		DataSource ds = null;
		try {
			Context ctx = new InitialContext();
			ds = (DataSource) ctx.lookup("java:comp/env/bookSystem");
			conn = ds.getConnection();
		} catch (NamingException e) {
			System.out.println(e.getMessage());
		}
		return conn;
	}
 

 The difference between connection pool and data source (source: http://blog.csdn.net/indieinside/article/details/40790231)

 

I personally think that the two are different:
(1) A data source is an interface provided by a database to programming, and each data source corresponds to a database.
(2) The connection pool is just a buffer pool for storing database connection objects. When a data connection is required, it can be taken from the buffer pool.
(3) The connection pool can manage data sources.


Using TCP to connect your application to the database is an expensive thing (a very time consuming thing), developers can use the connection pool to repeatedly use the database connection. Compared to using TCP to connect to the database for each request, the connection pool only creates a new TCP connection when there is no valid connection. When a connection is closed, it will be put into the pool and it will still keep the connection to the database, thus reducing the number of TCP connections to the database.
     Data source refers to the source of data, such as a database. A connection pool refers to such a "pool". Everything in the pool is a "connection" to the data source, so that when others want to connect to the data source, they can take it from this "pool" and put it back after use. For others who want to use it later.
The data source we generally refer to refers to the database~

 

Data source refers to the summary of the source of data, including database location and database type and other information, which is actually an abstraction of data connection.  It can also be said that you want to get a summary of where the information is stored (including a summary of the type of database where the information is stored, the address of the database, etc.).                 

 

 A connection pool refers to such a "pool":

 Everything in this pool is a "connection" to the data source,

 In this way, when others want to connect to the data source, they can take it from this "pool",

 After use, put it back for others who want to use it in the future.


The data source we generally refer to refers to the database~

To put it more vividly, the connection pool is like the agent of the data source.
If we need a connection (connection), we can directly ask him (connection pool) to ask for it, and we do not need to ask for the data source;
the unused connection is also directly returned to the connection. pool~~

That is to say, with the connection pool, we don't need to deal with the data source directly~
The connection pool is in the memory of the machine where your program is located, the data source is not necessarily~
and the data source and the connection pool will maintain a certain number of connections~
so that we can access When you use the database, you don't need to find a data source to connect to
. You can directly get the connection in the local memory, which can improve the performance of the program. The
above is so abstract. Let me use my own understanding to tell you
that each connection is like water. The water distribution pipe of the station, the connection pool is like a water station, and the source of the water station is like a database.
Connection pools can control other behaviors such as the number of split pipes.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327038253&siteId=291194637