By tigerhere on Aug 21, 2009
Download, Install, and Configure MySQL
Download MySQL 5.1: http://dev.mysql.com/downloads/mysql/5.1.html
File downloaded: mysql-5.1.37-win32.msi, about 100 meg
\* double click on mysql-5.1.37-win32.msi
\* Welcome page is displayed. Click Next.
\* Use default, Custom, click Next.
- Default installation directory (Destination Folder): C:\\Program Files\\MySQL\\MySQL Server 5.1\\
- Open MySQL Server branch, click on MySQL Server Datafiles, click Change button.
- Set destination folder (Data Folder) to C:\\sun\\mysql, click OK.
- Remove documentation from install
- To be installed: MySQL Server, Client Programs, MySQL Instance Manager.
- No other changes.
- Click Next.
\* Echoes the above selections. Click Install.
\* Software installs. MySQL notices come up. Click Next on each.
\* Wizard Completed is displayed. Configure the MysSQL Server now, is checked.
\* Welcome to the MySQL Server Instance Configuration Wizard is displayed. Click Next.
\* Choose Standard Configuration. Click Next.
\* Install As Windows Service is checked,
- Service Name: MySQL,
- Launch automatically is unchecked,
- Include Bin Directory in Windows PATH is checked.
- Click Next.
\* Enter a root password, example root. Click Next.
\* Ready to execute, is displayed. Click Execute.
\*\*\* The first time, it failed to start the server. I restarted my computer.
On restart, I click: Start/All Programs/MySQL/MySQL Server 5.1/MySQL Server Instance Configuration.
Note, I can run this at anytime.
The installation and configuration is completed. And an database instance has been created.
use the Windows Services Manager to start and stop the MySQL instance.
Create a Database
Sample simple commands: http://dev.mysql.com/doc/world-setup/en/world-setup.html
>mysql -u root -p mysql> create database studentdb; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | studentdb | | test | +--------------------+ 4 rows in set (0.00 sec) Now I have MySQL Server instance running, and a database created.
Modify the NetBeans Project to use MySQL
Under Services tab, Databases/Drivers, right mouse click MySQL (Connector/J driver) select Connect using.
In the popup, enter:
Name: MySQL (Connector/J driver) Host: localhost Port: 3306 Database: studentdb User Name: root Password: root Remember password is checked. Click OK
A connection is now under the Services tab, Databases. jdbc:mysql://localhost:3306/studentdb [root]
In the NetBeans Java EE EJB project:
Make a backup of the JavaDB persistence.xml file, which is under the project's setup folder: copy to persistenceJavaDB.xml.
In persistence.xml, I select Data Source: New Data Source ...
In the popup:
JNDI Name: mysql/studentdb Database Connection: jdbc:mysql://localhost:3306/studentdb [root] Click OK
Clean and build EJB project.
Clean and build Java EE project.
Deploy and test.
\*\*\* Works with the MySQL database.
View New Rows in the Database
Use either MySQL command line utility, or Connect and Execute command in NetBeans.
>mysql -u root -p mysql> use studentdb; Database changed mysql> show tables; Empty set (0.00 sec) mysql> show tables; +---------------------+ | Tables_in_studentdb | +---------------------+ | address | | dorm | | sequence | | student | | studentmajor | +---------------------+ 5 rows in set (0.00 sec) mysql> select \* from studentmajor; +----+---------+ | ID | NAME | +----+---------+ | 1 | English | | 2 | Science | +----+---------+ 2 rows in set (0.00 sec)
Done, tested, and verified!.
GlassFish Resource Configuration
In the above, the persistence resource is configured using NetBeans wizards.
Following are screen prints of the configurations created in GlassFish by NetBeans. This can be used to setup a resource in GlassFish, without using NetBeans.
GlassFish Resource Configuration on Solaris