To begin creating with JDBC, you should setup your JDBC condition by following the means appeared as follows. We expect that you are dealing with a Windows platform.

Install Java

Install J2SE Development Kit 5.0 (JDK 5.0) from Java Official Site.

Make beyond any doubt following condition factors are set as depicted underneath −

  • JAVA_HOME: This condition variable should point to the catalog where you introduced the JDK, for example C:\Program Files\Java\jdk1.5.0.

  • CLASSPATH: This condition variable ought to have proper ways set, for example C:\Program Files\Java\jdk1.5.0_20\jre\lib.

  • PATH: This condition variable should point to fitting JRE receptacle, for example C:\Program Files\Java\jre1.5.0_20\bin.

It is conceivable you have these variable set as of now, however just to ensure here's the manner by which to check.

  • Go to the control board and double tap on System. In the event that you are a Windows XP client, it is conceivable you need to open Performance and Maintenance before you will see the System icon.

  • Go to the Advanced tab and snap on the Environment Variables.

  • Now check if all the previously mentioned factors are set properly.

You consequently get both JDBC bundles java.sql and javax.sql, when you introduce J2SE Development Kit 5.0 (JDK 5.0).

Install Database

The most imperative thing you will require, obviously is a genuine running database with a table that you can question and modify.

Install a database that is most reasonable for you. You can have a lot of decisions and most regular are −

  • MySQL DB: MySQL is an open source database. You can download it from MySQL Official Site. We prescribe downloading the full Windows installation.

    In expansion, download and introduce MySQL Administrator just as MySQL Query Browser. These are GUI based devices that will make your improvement much easier.

    Finally, download and unfasten MySQL Connector/J (the MySQL JDBC driver) in an advantageous registry. With the end goal of this instructional exercise we will accept that you have introduced the driver at C:\Program Files\MySQL\mysql-connector-java-5.1.8.

    Accordingly, set CLASSPATH variable to C:\Program Files\MySQL\mysql-connector-java-5.1.8\mysql-connector-java-5.1.8-bin.jar. Your driver rendition may fluctuate dependent on your installation.

  • PostgreSQL DB: PostgreSQL is an open source database. You can download it from PostgreSQL Official Site.

    The Postgres establishment contains a GUI based regulatory instrument called pgAdmin III. JDBC drivers are likewise included as a major aspect of the installation.

  • Oracle DB: Oracle DB is a business database sold by Oracle . We accept that you have the fundamental conveyance media to introduce it.

    Oracle establishment incorporates a GUI based authoritative instrument called Enterprise Manager. JDBC drivers are additionally included as a piece of the installation.

Install Database Drivers

The most recent JDK incorporates a JDBC-ODBC Bridge driver that makes most Open Database Connectivity (ODBC) drivers accessible to software engineers utilizing the JDBC API.

Now a days, the greater part of the Database merchants are providing fitting JDBC drivers alongside Database establishment. Thus, you ought not stress over this part.

Set Database Credential

For this instructional exercise we are going to utilize MySQL database. When you introduce any of the above database, its director ID is set to root and offers arrangement to set a secret word of your choice.

Using root ID and secret word you can either make another client ID and secret word, or you can utilize pull ID and secret phrase for your JDBC application.

There are different database activities like database creation and erasure, which would require chairman ID and password.

For rest of the JDBC instructional exercise, we would utilize MySQL Database with username as ID and password as password.

If you don't have adequate benefit to make new clients, at that point you can ask your Database Administrator (DBA) to make a client ID and secret phrase for you.

Create Database

To make the EMP database, utilize the accompanying advances −

Step 1

Open a Command Prompt and change to the establishment catalog as pursues −

C:\> 

C:\>cd Program Files\MySQL\bin 

C:\Program Files\MySQL\bin>

Note: The way to mysqld.exe may shift contingent upon the introduce area of MySQL on your framework. You can likewise check documentation on the best way to begin and stop your database server.

Step 2

Start the database server by executing the accompanying order, in the event that it is now not running.

C:\Program Files\MySQL\bin>mysqld 

C:\Program Files\MySQL\bin>

Step 3

Create the EMP database by executing the accompanying order −

C:\Program Files\MySQL\bin> mysqladmin make EMP -u root -p 

Enter password: ******** 

C:\Program Files\MySQL\bin>

Create Table

To make the Employees table in EMP database, utilize the accompanying advances −

Step 1

Open a Command Prompt and change to the establishment catalog as pursues −

C:\> 

C:\>cd Program Files\MySQL\bin 

C:\Program Files\MySQL\bin>

Step 2

Login to the database as pursues −

C:\Program Files\MySQL\bin>mysql -u root -p 

Enter password: ******** 

mysql>

Step 3

Create the table Employee as pursues −

mysql> use EMP; 

mysql> make table Employees 

-> ( 

-> id int not null, 

-> age int not null, 

-> first varchar (255), 

-> last varchar (255) 

-> ); 

Query OK, 0 lines influenced (0.08 sec) 

mysql>

Create Data Records

Finally you make few records in Employee table as pursues −

mysql> INSERT INTO Employees VALUES (100, 18, 'Zara', 'Ali');
Query OK, 1 push influenced (0.05 sec) 

mysql> INSERT INTO Employees VALUES (101, 25, 'Mahnaz', 'Fatma'); 

Query OK, 1 push influenced (0.00 sec) 

mysql> INSERT INTO Employees VALUES (102, 30, 'Zaid', 'Khan'); 

Query OK, 1 push influenced (0.00 sec) 

mysql> INSERT INTO Employees VALUES (103, 28, 'Sumit', 'Mittal'); 

Query OK, 1 push influenced (0.00 sec) 

mysql>

For a total comprehension on MySQL database, examine the MySQL Tutorial.

Now you are prepared to begin exploring different avenues regarding JDBC. Next section gives you an example precedent on JDBC Programming.







© Javacodegeeks © 2019 - 2019
All Right Reserved and you agree to have read and accepted our term and condition.

Python 3