I.Server.xml configuration data source:
Parameter Description: 1.Resource 1) Name Specifies the JDNI Name 2) Auth Specifies the management of the resource. There are two options Container and Application Container represents the container to create and manage the resource application representation by the web application. Creating and Managing Resource 3) Type Specifies the Java Class Name of Resource Associated 2.ResourceParam 1) Factory Specifies the Max Name of the Factory Generation DataSource to specify the maximum number of database connections in the database connection pool 3) MaxIdle specified database Maximum number of database connections in the connection pool 4) MaxWait Specifies the longest time in the database connection in the database connection pool. The unit is in milliseconds, which will throw an exception in this time. Take the value is -1 Represents the username that can be waited indefinitely 5) Username Specifies the connection database 6) Password specifies the password of the connection database 7) DRIVERCLASSNAME Specifies the JDBC driver for the connection database 8) URL Specifies the URL II .Web.xml Statement to JDNI References of Resource
Parameter Description: Description: Res-Ref-name: Specifies the JDNI history word of the reference resource, corresponding to the name word of the reference resource with the Name property in
II. Access Data Source 1) Find data sources, generate java.sql.datasoruce reference javax.nameing.context provides the interface of the JDNI Resource for the interface CONTEXT CTX = New InitialContext (); DataSource DS = (Datasource) CTX.lookup ("Java: Comp / env / jdbc / bookdb "); 2) Get the connection connection con = ds.getConnection ();
3) Turn off the connection con.close (); close () method, return the connection to the database connection pool, so that the Connection is restored to the short status of the four .JSP application example (omitted) 5. Compare JDBC