The NetBeans E-commerce Tutorial - Setup Instructions

This tutorial needs a review. You can edit it in GitHub following these contribution guidelines.

Tutorial Contents

netbeans stamp 68 69
Figure 1. Content on this page applies to NetBeans IDE, versions 6.8 and 6.9

If you want to follow a tutorial unit without having completed previous units, you need to perform some preliminary steps in order to set up your development environment.

  1. Set up your MySQL database server. Follow the steps outlined in: Communicating with the Database Server.

  2. Create the affablebean schema on the database server, and populate the database with sample data:

    1. Click on affablebean.sql and copy (Ctrl-C; ⌘-C on Mac) the entire contents of the file.

    2. Open the IDE’s SQL editor. In the Services window (Ctrl-5; ⌘-5 on Mac), right-click the affablebean database connection ( db connection node ) node and choose Execute Command.

execute command
Figure 2. Choose Execute Command from a connection node to open the IDE’s SQL editor

The IDE’s SQL editor opens.

  1. Paste (Ctrl-V; ⌘-V on Mac) the entire contents of the affablebean.sql file into the editor.

  1. Click the Run SQL ( run sql btn ) button in the editor’s toolbar. The script runs on your MySQL server. Tables are generated for the database, and sample data is added to the product and category tables.

  1. Create a connection pool and JDBC resource on GlassFish.

    1. In the Services window (Ctrl-5; ⌘-5 on Mac), expand the Servers > GlassFish Server 3 node and choose Properties. In the Servers window that displays, make sure the 'Enable JDBC Driver Deployment' option is selected. If your project requires the MySQL Connector/J driver, this option will ensure that the driver is deployed to GlassFish when your project is deployed. (If the server is already running, you’ll need to restart the server.)

    2. In the Services window, right-click the GlassFish Server 3 node and choose Start.

    3. Once the server is running, right-click the GlassFish Server 3 node and choose View Admin Console.

    4. Log into the console (default username/password is: admin/adminadmin).

    5. In the Admin Console, in the Tree on the left, expand the Resources > JDBC node, then click the Connection Pools node.

    6. In the Connection Pools interface, click the New button, and enter the following details:

      • Name: AffableBeanPool

      • Resource Type: javax.sql.ConnectionPoolDataSource

      • Database Vendor: MySql

connection pool
Figure 3. Specify settings to create a connection pool that connects with a MySQL database
  1. Click Next. Accept all defaults and click Finish.

  1. In the Connection Pools interface, click on your newly created AffableBeanConnectionPool to make the following change under the General tab:

    • Datasource Classname: com.mysql.jdbc.jdbc2.optional.MysqlDataSource

datasource classname
Figure 4. Set the datasource classname for the connection pool
  1. Click Save.

  1. Click the Additional Properties tab and ensure that the following three properties have been set. (There may be other properties listed - these are default settings, however the following three must be set manually.)

    • User: root

    • Password: nbuser

    • URL: jdbc:mysql://localhost:3306/affablebean

additional properties
Figure 5. Set username, password and url to the database
  1. Click Save.

  1. Click the General tab, then click Ping. You should see a message indicating that the ping succeeded. The AffableBeanPool connection pool can now connect to your MySQL database server.

ping succeeded
Figure 6. Ping the MySQL server to determine whether the connection pool can connect
  1. In the Admin Console’s Tree in the left column, click the Resources > JDBC > JDBC Resources node. The JDBC Resources interface opens in the main window.

  1. Click the New button to create a new JDBC resource, then enter the following details:

    • JNDI Name: jdbc/affablebean

    • Connection Pool: AffableBeanPool

jdbc resource
Figure 7. Specify JNDI name and connection pool to create the JDBC resource
  1. Click OK.

You have set up the MySQL server and can connect to it from the IDE’s Services window. You created a database named affablebean, and populated the database’s product and category tables with sample data. You then started the GlassFish server, and created a connection pool that enables the server to connect to the affablebean database. Finally, you created a JDBC resource which your application can use to reference the server’s connection pool.

You can now open and run any of the project snapshots provided for you in the tutorial units.