0% found this document useful (0 votes)
4 views

3

The document provides an overview of Java Database Connectivity (JDBC) with sample SQL queries for creating and managing database tables, including examples for creating 'COURSE' and 'STUDENT' tables, and performing CRUD operations. It discusses the importance of databases over files for data storage, highlighting issues such as redundancy, inconsistency, and security. Additionally, it introduces JDBC technology and its role in facilitating database operations in Java applications.

Uploaded by

chaithu kasa11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

3

The document provides an overview of Java Database Connectivity (JDBC) with sample SQL queries for creating and managing database tables, including examples for creating 'COURSE' and 'STUDENT' tables, and performing CRUD operations. It discusses the importance of databases over files for data storage, highlighting issues such as redundancy, inconsistency, and security. Additionally, it introduces JDBC technology and its role in facilitating database operations in Java applications.

Uploaded by

chaithu kasa11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Java Database Connectivity(JDBC)

-------------------------------------------------------------
Sample Queries:
1) I want to create Course table with columns
Course_id course_name Duration start_date

CREATE TABLE COURSE (


COURSE_ID NUMBER(8),
COURSE_NAME VARCHAR2(20),
DURATION VARCHAR2(20),
START_DATE DATE,
PRIMARY KEY(COURSE_ID)
);

2) I want to create STUDENT table with columns


Roll_number section name marks

CREATE TABLE STUDENT (


ROLL_NUMBER NUMBER(6),
SECTION VARCHAR2(5),
NAME VARCHAR2(10),
MARKS NUMBER(5)
);

In the above table we can’t use roll_number as a


primary key, because same roll_number can exist in
Another section also.
In this case we have to use composite primary key.
Composite primary key means, combination of two or
more columns are acting as a primary key in the table.
The correct query for the above.
CREATE TABLE STUDENT (
ROLL_NUMBER NUMBER(6),
SECTION VARCHAR2(5),
NAME VARCHAR2(10),
MARKS NUMBER(5),
PRIMARY KEY(ROLL_NUMBER, SECTION)
);

PRIMARY KEY = UNIQUE + NOT NULL

STUDENT
ROLL_NUMBER SECTION NAME MARKS
101 A SUNIL 699
102 A ANIL 599
101 B KETHAN 489
102 B SURAJ 571

3) I want to insert record into COURSE table.

INSERT INTO COURSE VALUES(1001, ‘JAVA FS’, ‘6


MONTHS’, ’21-FEB-24’);
(or)
INSERT INTO COURSE(COURSE_ID, DURATION,
COURSE_NAME, START_DATE) VALUES(
1002, ‘5 MONTHS’, ‘PYTHON FS’, ’25-FEB-24’);
4) I want to update duration of all courses which are
starting in the month of February.
Query-1:
UPDATE COURSE SET DURATION = ‘4 MONTHS’
WHERE START_DATE LIKE ‘%FEB%’;
Query-2:
UPDATE COURSE SET DURATION = ‘4 MONTHS’
WHERE START_DATE BETWEEN ‘1-FEB-24’ TO ’29-FEB-
24’;
Query-3:
UPDATE COURSE SET DURATION = ‘4 MONTHS’ WHERE
TO_CHAR(START_DATE, ‘MON’) = ‘FEB’;

5) I want to display the student name and section who got


the highest marks in each section.
SELECT NAME, SECTION, MAX(MARKS) AS ‘HIGHEST
MARKS’ FROM STUDENT GROUP BY SECTION;

Date: 22/02/2024

Installing Oracle Database:


1. Enterprise Edition
2. Express Edition
Enterprise Edition has more features compared to
Express Edition. Enterprise Edition occupies more
memory and impacts on your system performance.
So, for learning/practicing, you can install light weight
Software called express edition.
Visit:
https://www.oracle.com/database/technologies/xe-
downloads.html
Click on
Oracle Express Edition 21c windows x64
OracleXE213_Win64.zip file will be downloaded.
Extract the zip file, then go to the extracted folder and
Double click on setup.exe file to install the software.

Display the list of employees whose salary is more than


the salary of ALLEN

SELECT * FROM EMP WHERE SAL > (


SELECT SAL FROM EMP WHERE
ENAME = 'ALLEN'
);

Display the name of the employee who is getting


highest salary.

SELECT ENAME FROM EMP WHERE SAL IN (


SELECT MAX(SAL) FROM EMP
);

Create a table Hotel with columns hotel_id


hotel_name phone and rating
Create a table Rooms with columns room_id
room_type rent and hotel_id
CREATE TABLE HOTEL (
HOTEL_ID NUMBER(8) PRIMARY KEY,
HOTEL_NAME VARCHAR2(20),
PHONE NUMBER(10),
RATING NUMBER(5,2)
);
CREATE TABLE ROOMS (
ROOM_ID NUMBER(8) PRIMARY KEY,
ROOM_TYPE VARCHAR2(20),
RENT NUMBER(8),
HOTEL_ID NUMBER(9) REFERENCES
HOTEL(HOTEL_ID)
);

Q) create dept table with columns deptno,dname and


loc
Q) create emp table with columns empno, ename, sal,
hiredate and deptno.
Insert some sample records into both the tables.

Introduction to JDBC:

 Data in a java program can exist in variables or objects.


 Data exist in variables or objects is a temporary data.
Which means, whenever the scope of that variable or
object is completed then we lose the data.
 So, to use the data in future, we have to store it in a
permanent memory. Which is nothing but a file or a
database.

Date : 23/02/2024
 What are the issues with files?
1. Searching for a specific data in a file will be a time
consuming task.
2. Same data can be stored multiple times in a file. So it
leads to redundant data/duplicate data. The problem
is memory space will be wasted.
3. When data is stored across multiple files then
retrieving the related information/data from the files
is a tedious task.
4. When data exist in multiple files, if the data is
modified at one file and not modified at another file
then it leads to data inconsistency.
5. The data stored in files is not secured. Because, once
a file a opened all the data of that file will be visible.
 All the above issues we can overcome with the
Databases.

What operations can be done on the data?

CRUD operations.
C – create ( creating the data / inserting the data)
R – Read ( retrieving the data/selecting the data)
U – Update ( updating the data/modifying the data)
D – Delete ( deleting the data / removing the data)
JDBC Technology:
Technology  refers to the tools and techniques to
solve the problems.
API  Java Library or Java API both are same.
Java API refers to a collection of
pre-defined/pre-existing programs given by the
programming language to develop user-defined
applications.

You might also like