Install Java:
Install J2SE Developer Kit 5.0 (JDK 5.0) Download: Java official website.
Make sure the following environment variable settings are set, as described below:
Java_home: This environment variable should point to the directory where the JDK is installed, for example: C:\Program files\java\jdk1.5.0
CLASSPATH: This environment variable should have the appropriate path set, such as: C:\Program files\java\jdk1.5.0_20\jre\lib
PATH: This environment variable should point to the appropriate JRE bin, such as: C:\Program Files\java\jre1.5.0_20\bin.
There may already be settings for these variables, but just to make sure here is how to check.
Go to the Control Panel and double-click the System. If a user of Windows XP is likely to be turned on: "Performance" = "Maintenance", you will see the System icon.
Go to the Advanced tab, and then click Environment Variables.
Now, select all the input variables set correctly.
will automatically get the JDBC package java.sql and javax.sql when installing the J2SE Development Kit 5.0 (JDK 5.0)
To install the database:
will need to be of course, the most important is the actual running of the database used, can query and modify the table.
Installing the database is most appropriate. There are many choices, the most common of which are:
MySQL Db:mysql is an open source database. You can download the official MySQL website from here and recommend downloading the full Windows installation.
In addition, download and install MySQL admin as well as MySQL query browser. These are all GUI based tools that will make development easier.
Finally, please download and unzip the MySQL connector/j (MySQL jdbc driver) in a convenient directory. For the purposes of this tutorial, we will assume that the driver is already installed in C:\Program files\mysql\mysql-connector-java-5.1.8.
Set the CLASSPATH variable accordingly to C:\Program Files\mysql\mysql-connector-java-5.1.8\mysql-connector-java-5.1.8-bin.jar. Depending on the version of the driver that is installed, it may be different.
PostgreSQL Db:postgresql is an open source database. You can download the PostgreSQL official website from here.
The Postgres installation contains a GUI-based management tool called Pgadmin III. The JDBC driver is also included as part of the installation.
Oracle Db:oracle Database is a commercial database for Oracle sales. Suppose you have the necessary distribution media to install.
Oracle's installation includes a GUI-based management tool called Enterprise Manager. The JDBC driver is also included as part of the installation.
To install the database driver:
The latest JDK contains the JDBC-ODBC bridge driver, which enables most open Database connectivity (ODBC) driver programmers to use the JDBC API.
Most database vendors now provide the appropriate JDBC driver with the database installation. So, you should not worry about this part.
To set up Database authentication:
In this tutorial, we will use the MySQL database. When any of the above databases are installed, its administrator ID is set to root and a password for the specified setting is given.
With root and password, you can create another user ID and password, or you can use root and password in the JDBC application.
There are various database operations, such as database creation and deletion, which will require an administrator ID and password.
For the remainder of the JDBC tutorial, we will use the MySQL database username as the ID and password as the password.
If you do not have sufficient permissions to create a new user, you can have the database administrator (DBA) create a user ID and password for you.
To create a database:
To create an EMP database, use the following procedure:
Step 1:
Open the command prompt and change to the installation directory as follows:
Copy Code code as follows:
C:\>
C:\>CD program Files\mysql\bin
C:\Program files\mysql\bin>
Note: Depending on the installation location on the MySQL system, the Mysqld.exe path may be different. You can also view information about how to start and stop a database server document.
Step 2:
By executing the following command, if it does not run the start database server.
Copy Code code as follows:
C:\Program Files\mysql\bin>mysqld
C:\Program files\mysql\bin>
Step 3:
Create the database EMP by executing the following command
Copy Code code as follows:
C:\Program files\mysql\bin> mysqladmin Create Emp-u root-p
Enter Password: ********
C:\Program files\mysql\bin>
Create a table
To create an EMP database in the Employees table, follow these steps:
Step 1:
Open the command prompt and change to the installation directory as follows:
Copy Code code as follows:
C:\>
C:\>CD program Files\mysql\bin
C:\Program files\mysql\bin>
Step 2:
Log in to the database as shown below
Copy Code code as follows:
C:\Program Files\mysql\bin>mysql-u Root-p
Enter Password: ********
Mysql>
Step 3:
Create an employee table as follows:
Copy Code code as follows:
mysql> use EMP;
Mysql> CREATE TABLE Employees
-> (
-> ID int NOT NULL,
-> Age int is not NULL,
->-varchar (255),
-> last varchar (255)
->);
Query OK, 0 rows affected (0.08 sec)
Mysql>
Create a data record
Finally, create some records in the employee table as follows:
Mysql> INSERT into Employees VALUES (+, ' Zara ', ' Ali ');
Query OK, 1 row affected (0.05 sec)
Mysql> INSERT into Employees VALUES (+, ' Mahnaz ', ' Fatma ');
Query OK, 1 row Affected (0.00 sec)
Mysql> INSERT into Employees VALUES (102, ' Zaid ', ' Khan ');
Query OK, 1 row Affected (0.00 sec)
Mysql> INSERT into Employees VALUES (sumit, ' Mittal ');
Query OK, 1 row Affected (0.00 sec)
Mysql> a complete knowledge of MySQL database, learn the MySQL tutorial.
Now, you can start using JDBC attempts. The next tutorial will give you a sample example of JDBC programming.