Java & MySQL
Java programs can connect to MySQL using the JDBC API. JDBC works with Java across multiple platforms such as Windows, Mac OS, and various versions of UNIX.
1. Definition
JDBC stands for Java Database Connectivity, which is a standard Java API for establishing database-independent connections between Java applications and databases.
The JDBC library includes APIs for the various tasks commonly associated with database usage, including those described below.
- Making
a connection to a database.
- Creating
SQL or MySQL statements.
- Executing
SQL or MySQL queries in the database.
- Viewing
& Modifying the resulting records.
2. Installing MySQL
In this section, we will use AppServ (Apache + PHP + MySQL) as an example to demonstrate how MySQL can be installed and used with Java applications.
Installation Steps
1. Prepare the Installation Package
Download the AppServ software from http://www.appserv.org. You can choose the version that matches your operating system.
Step-by-Step Installation of AppServ
Step 1:
Double-click the appserv-win32 or appserv-win64 installation file to begin installing AppServ on your computer.
AppServ is distributed under the GNU/GPL License. You should read the license agreement before proceeding with the installation. If you agree to the terms of the license, click Next to continue to the next step. If you do not agree, click Cancel to terminate the installation process.
The default installation directory for AppServ is C:\AppServ. If you want to install AppServ in a different location, click the Browse button and select your preferred destination folder. Then, click Next to proceed to the next step.
Step 4: Select Components
By default, all AppServ package components are selected for installation. If you want to install only specific components, you can select or deselect them by clicking the corresponding check boxes.
The components included in AppServ are:
- Apache HTTP Server – A web server used to host websites and web applications.
- MySQL Database – A database server used to store and manage data.
- PHP Hypertext Preprocessor (PHP) – A server-side scripting language processor for developing dynamic web applications.
- phpMyAdmin – A web-based tool for managing and controlling MySQL databases through a web browser.
After selecting the desired components, click Next to proceed to the next step.
Step 5: Apache Configuration
This screen is used to configure the Apache settings.
- Server Name: You must specify the server name, for example, www.appserv.org.
- Admin Email: You must specify the administrator's email address, for example, root@appserv.org.
- HTTP Port: You must specify the HTTP port that the Apache Web Server will use to accept client requests.
After entering the required information, click Next to continue to the next step.
Step 6: MySQL Configuration
In this step, you need to configure the MySQL database settings.
- Root Password: You must enter a password for the MySQL root user.
- Default User: The default username for this password is root.
- Character Set: Specifies the character encoding used for data storage and database connections.
- Old Password Option: Enable this option if you encounter issues when using PHP code with older MySQL APIs.
- If you receive the error message "Client does not support authentication protocol requested by server; consider upgrading MySQL client", it may indicate a compatibility problem between the MySQL server and the client application.
- To avoid this error, you should check the appropriate compatibility option during the configuration process.
After completing the MySQL configuration, click Install or Next (depending on the version) to continue with the installation.
Step 7: Complete the AppServ Installation
After the installation is completed, AppServ will prompt you to start the Apache and MySQL services immediately. Click Finish to complete the installation process and make AppServ ready for use.
Once finished, Apache and MySQL will be available for running web applications and database services on your computer.
After the installation is complete, open a web browser and type localhost in the address bar. If AppServ has been installed successfully, the browser will display the AppServ welcome page as shown below. This indicates that the Apache web server is running correctly and AppServ is ready to use.
After successfully installing AppServ, the next step is to configure PHP. Navigate to the D:\AppServ\www directory, locate the file named index.php, and rename it to index1.php.
This step prevents the default AppServ PHP page from loading automatically and allows you to create and test your own PHP files in the web root directory.
After that, click on the phpMyAdmin link to open the phpMyAdmin administration interface.
After a successful login, the following screen will be displayed:

