Configure the glassfish server in netbeans
1. Start the glassfish server and enter http: // localhost: 4848/in the address bar to enter the server configuration interface, as shown below:
2. Select JDBC of resources under common tasks. The JDBC resources and connection pools are displayed as follows:
3. Click the new button in the connection pool to create a connection pool jdbc_test, as shown below:
Click Next, as shown below:
Keep other parameter configurations by default. Click finsh.
Click jdbc_test to display the following configuration interface:
Set the parameters on the general and advanced interfaces by default. Click
Additionalproperties (other properties) to enter the configuration interface:
Click Add property)
Portnumber 3306
Driverclass com. MySQL. JDBC. Driver
Zerodatetimebehavior converttonull
Databasename db_test
User Root
Url jdbc: mysql: // 127.0.0.1: 3306/db_test
Servername 127.0.0.0
Password Admin
Transformedbitlsboolean true
4. After configuration, go to the general (general) configuration page and click the ping button. If the following page appears, the connection pool is successfully created.
NOTE: If javax. resource. resourceexception: Class Name Is Wrong orclasspath is not set for: COM. mySQL. JDBC. jdbc2.optional. mysqldatasource this error is because the MySQL driver package mysql-connector-java-5.1.20-bin.jar is not placed in the glassfish installation directory Domains \ domain1 \ Lib \ ext;
Solution: Put the MySQL driver package mysql-connector-java-5.1.20-bin.jar under the glassfish installation directory Domains \ domain1 \ Lib \ ext and restart the glassfish server.
5. After the connection pool is successfully created, click JDBC resources. On the JDBC resource configuration page, the pool name (connection pool name) displays the jdbc_test connection pool that has just been configured. The configuration interface is as follows:
6. On the configuration page, configure the JNDI name JDBC/test (this name can be obtained by yourself). Now, the connection pool and data source are configured.
7. test whether the data source is successfully connected:
Create a project in netbeans and use Java
Web category. The code for selecting index. jsp of a Web application is as follows:
<% @ Pagecontenttype = "text/html" pageencoding = "UTF-8" %> <% @ pageimport = "javax. naming. * "%> <% @ pageimport =" javax. SQL. * "%> <% @ pageimport =" Java. SQL. * "%> <HTML>
8. Run the project directly. If the following interface is displayed, the project runs successfully.