[go: up one dir, main page]

0% found this document useful (0 votes)
13 views42 pages

Bhanusoc 4

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

Bhanusoc 4

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

SKILL ORIENTED COURSE -IV ON

“Java Full Stack Development”


Submitted in partial fulfillment of the requirements for award of the degree of

BACHELOR OF TECHNOLOGY

In

ELECTRONICS AND COMMUNICATION TECHNOLOGY

By

R. Bhanu Sri Mounika

(21A81A1455)

Under the Esteemed Coordination of

Dr. M. THAMARAI M. E, Ph. D


Professor

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

SRI VASAVI ENGINEERING COLLEGE (AUTONOMOUS)


Sponsored by Sri Vasavi Educational Society

(Approved by AICTE, New Delhi and Permanently Affiliated to JNTUK, Kakinada)

(Accredited by NBA & NAAC with ‘A’ Grade)

Pedatadepalli,TADEPALLIGUDEM,W.G.Dist.,A.P-534101

Academic Year:2023-2024
SRI VASAVI ENGINEERING COLLEGE (AUTONOMOUS)
Sponsored by Sri Vasavi Educational Society

(Approved by AICTE, New Delhi and Permanently Affiliated to JNTUK, Kakinada)

(Accredited by NBA & NAAC with ‘A’ Grade) Pedatadepalli,

TADEPALLIGUDEM,W.G.Dist.,A.P-534101

DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING

CERTIFICATE
This is to certify that the Skill Oriented Course-IV report entitled “JAVA FULL
STACK DEVELOPMENT” is a bonafide work done by R.BHANU SRI
MOUNIKA (21A81A1455) submitted in partial fulfilment of the requirements
for award of the Degree in Electronics and Communication Technology during
the academic Year 2023-2024. The results of investigation enclosed in this
report have been verified and found satisfactory.

SOC COORDINATOR HEAD OF THE DEPARTMENT


Dr . M. THAMARAI M. E .,Ph. D Dr .E. KUSUMA KUMARI, M.Tech ., Ph. D
Professor HOD & Professor

EXTERNAL EXAMINER
ACKNOWLEDGEMENT

We would like to thank our Skill Oriented Coordinator Dr. M. THAMARAI M.E., Ph .D for
the guidance and help throughout the development of the Skill Oriented Course-IV on “JAVA
FULL STACK DEVELOPMENT” by providing us the required information. without his
supervision, support, and encouragement. We would not gain awareness of many new things
during this Course.

We would like to thank Dr. E. KUSUMAKUMARI, M. Tech., Ph. D Head of the Department
of Electronics & Communication Engineering for supporting us to do our Skill Oriented
Course Successfully.

We would like to sincerely thank Principal of our college, Dr. G.V.N.S.R. RATNAKAR
RAO, B.E, M.E, Ph. D. for his constant support throughout the Skill Oriented Course.

An Endeavour over long period can also be successful by constant effort and encouragement.
We wish to take this opportunity to express our deep gratitude to all the people who have
extended their cooperation in various ways during our Skill Oriented Course. It is our pleasure
to acknowledge the help of all those respected individuals.

R.BHANU SRI MOUNIKA


( 21A81A1455)
SRI VASAVI ENGINEERING COLLEGE
DEPARTMENT OF ELECTRONICS & COMMUNICATION
ENGINEERING
Skill Oriented Course for the Academic Year: (2023-2024)

SKILL ORIENTED COURSE

Name of the Student : R. Bhanu Sri Mounika

Roll Number : 21A81A1455

Program : B. Tech

Branch : Electronics and Communication Technology

Topic : JAVA FULL STACK DEVELOPMENT

Coordinator : Dr. M. THAMARAI M.E., Ph .D


TABLE OF CONTENTS

S.NO TITLE PAGE NO

1. INTRODUCTION 1-7
1.1 Advanced Java 1
1.2 Difference of Core Java and Advanced Java 2
1.3 JDBC Architecture 2-7

2. SERVLETS 8-12
2.1 Servlets API 9
2.2 Web Servers 10
2.3 Web Clients 11
2.4 Java Server Pages (JSP) 12

3. BASICS OF HTML 13-15


3.1 What is HTML 13
3.2 Description of HTML 14
3.3 Features of HTML 14-15

4. SQL DATA BASE 16-21


4.1 SQL 16
4.2 Types of SQL 17-21

5. INTERFACING JAVA WITH DATA BASE 22-28

6. PROGRAMS 29-34

7. CONCLUSION 35
REFERANCE 36
ABSTRACT

Java Full Stack Development, coupled with robust database integration, forms the
backbone of modern web applications. This abstract offers a comprehensive overview of Java
Full Stack Development and its symbiotic relationship with databases, elucidating their combined
role in crafting scalable, dynamic, and data-driven web solutions.

At the heart of Java Full Stack Development lies the integration of databases, serving as
repositories for storing, retrieving, and managing application data. Relational databases like
MySQL, PostgreSQL, or Oracle, as well as NoSQL databases like MongoDB, offer versatility in
accommodating diverse application requirements, from structured data storage to flexible
document-oriented databases. Advanced Java includes special tools and frameworks like Servlets,
JSP, Spring MVC, and Hibernate.

They handle the behind-the-scenes work of websites, like processing user requests and
managing data.HTML is like the blueprint of a website, deciding how everything looks and fits
together. When combined with Advanced Java, HTML makes sure websites can show dynamic
content and respond to user actions. MySQL is a popular database system that stores and
organizes website data, like user profiles or product information. Advanced Java connects with
MySQL to handle data smoothly, making sure everything works as it should.

This abstract serves as a guide to understanding the symbiotic relationship between Java
Full Stack Development and databases, showcasing their pivotal role in shaping the landscape of
modern web applications and paving the way for innovation in the digital era.
1.INTRODUCTION

1.1 What is Advanced Java?

Java is divided into two parts i.e. Core Java (J2SE) and Advanced Java (JEE). The core
Java part covers the fundamentals (data types, functions, operators, loops, thread, exception
handling, etc.) of the Java programming language. It is used to develop general purpose
applications. Whereas Advanced Java covers the standard concepts such as database
connectivity, networking, Servlet, web-services, etc. In this section, we will discuss what is
advance Java, its benefit, uses, topics of advance Java, and the difference between core Java
and advance Java.

Advance Java

It is a part of Java programming language. It is an advanced technology or advance version


of Java specially designed to develop web-based, network-centric or enterprise applications. It
includes the concepts like Servlet, JSP, JDBC, RMI, Socket programming, etc. It is a
specialization in specific domain.

Most of the applications developed using advance Java uses tow-tier architecture i.e. Client
and Server. All the applications that runs on Server can be considered as advance Java
applications.

Why advance Java?


o It simplifies the complexity of a building n-tier application.
o Standardizes and API between components and application sever container.
o JEE application Server and Containers provides the framework services.

Benefits of Advance Java

The four major benefits of advance Java that are, network centric, process simplification, and
futuristic imaging standard.

o JEE (advance Java) provides libraries to understand the concept of Client-Server


architecture for web- based applications.
o We can also work with web and application servers such as Apache
Tomcat and Glassfish Using these servers, we can understand the working of HTTP
protocol. It cannot be done in core Java.
o It is also important understand the advance Java if you are dealing with trading technologies
like Hadoop, cloud-native and data science.
o It provides a set of services, API and protocols, that provides the functionality which is
necessary for developing multi-tiered application, web-based application.

1
1.2 Difference between Core Java and Advance Java

Criteria Core Java Advance Java

Used for It is used to develop general purpose It is used to develop web-based applications.
application.

Purpose It does not deal with database, socket It deals with socket programming, DOM, and
programming, etc. networking applications.

Architecture It is a single tier architecture. It is a mute-tier architecture.

Edition It is a Java Standard Edition. It is a Java Enterprise Edition.

Package It provides java.lang.* package. It provides java.servlet.* package.

Advance Java Topics

o Basics of a Web application

o Web Container and Web Application

o Servlets

o JSPs

1.3 JDBC architecture

JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute
the query with the database. It is a specification from Sun Microsystems that provides a standard
abstraction(API or Protocol) for Java applications to communicate with various databases. It
provides the language with Java database connectivity standards. It is used to write programs
required to access databases. JDBC, along with the database driver, can access databases and
spreadsheets. The enterprise data stored in a relational database(RDB) can be accessed with the
help of JDBC APIs.

JDBC is an API(Application programming interface) used in Java programming to interact


with databases. The classes and interfaces of JDBC allow the application to send requests made
by users to the specified database. The current version of JDBC is JDBC 4.3, released on
21st September 2017.

2
There are four types of JDBC drivers defined by Sun Microsystem that are mentioned below:

• Type-1 driver or JDBC-ODBC bridge driver


• Type-2 driver or Native-API driver
• Type-3 driver or Network Protocol driver
• Type-4 driver or Thin driver

Type-1 driver

JDBC-ODBC bridge driver

Type-1 driver or JDBC-ODBC bridge driver uses ODBC driver to connect to the
database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function
calls. Type-1 driver is also called Universal driver because it can be used to connect to any of the
databases.

3
Advantages
• This driver software is built-in with JDK so no need to install separately.
• It is a database independent driver.
Disadvantages
• As a common driver is used in order to interact with different databases, the data transferred
through this driver is not so secured.
• The ODBC bridge driver is needed to be installed in individual client machines.
• Type-1 driver isn’t written in java, that’s why it isn’t a portable driver.

Type-2 driver

Native-API driver – Type 2 driver ( Partially Java driver):

The Native API driver uses the client -side libraries of the database. This driver converts
JDBC method calls into native calls of the database API. In order to interact with different
database, this driver needs their local API, that’s why data transfer is much more secure as
compared to type-1 driver. This driver is not fully written in Java that is why it is also called
Partially Java driver.

Advantage
• Native-API driver gives better performance than JDBC-ODBC bridge driver.

4
Disadvantages
• Driver needs to be installed separately in individual client machines
• The Vendor client library needs to be installed on client machine.
• Type-2 driver isn’t written in java, that’s why it isn’t a portable driver
• It is a database dependent driver.

Type-3 driver

Network Protocol driver – Type 3 driver (fully Java driver):

The Network Protocol driver uses middleware (application server) that converts
JDBC calls directly or indirectly into the vendor-specific database protocol. Here all the database
connectivity drivers are present in a single server, hence no need of individual client-side
installation.

5
Advantages
• Type-3 drivers are fully written in Java, hence they are portable drivers.
• No client side library is required because of application server that can perform many tasks
like auditing, load balancing, logging etc.
• Switch facility to switch over from one database to another database.

Disadvantages
• Network support is required on client machine.
• Maintenance of Network Protocol driver becomes costly because it requires database-specific
coding to be done in the middle tier.

Type-4 driver

Thin Driver or Native protocol Driver:

Type-4 driver is also called native protocol driver. This driver interacts directly with the database.
It does not require any native database library, that is why it is also known as Thin Driver.It is
fully written in Java language, hence they are portable drivers.

Type-4 JDBC driver also known as ‘thin driver’ or Direct to Database Pure Java Driver. It is
portable, the fastest among all JDBC drivers and database dependent.The thin driver converts
JDBC calls directly into the vendor-specific database protocol. It is fully written in Java
language. Also, it is a platform-independent driver but it is database dependent as it uses a native
protocol(Protocol can establish a connection between particular server only).

6
Advantage:
o Better performance than all other drivers.
o No software is required at client side or server side.

Disadvantage:
o Drivers depend on the Database.

7
2.SERVLETS
Servlet technology is used to create a web application (resides at server side and generates a
dynamic web page).

Servlet technology is robust and scalable because of java language. Before Servlet, CGI
(Common Gateway Interface) scripting language was common as a server-side programming
language. However, there were many disadvantages to this technology. We have discussed these
disadvantages below.

There are many interfaces and classes in the Servlet API such as Servlet, GenericServlet,
HttpServlet, ServletRequest, ServletResponse, etc.

• Servlet is an API that provides many interfaces and classes including documentation.
• Servlet is an interface that must be implemented for creating any Servlet.
• Servlet is a class that extends the capabilities of the servers and responds to the incoming
requests. It can respond to any requests.
• Servlet is a web component that is deployed on the server to create a dynamic web page.

8
2.1 Servlet API
• Servlet API
• Interfaces in javax.servlet package
• Classes in javax.servlet package
• Interfaces in javax.servlet.http package
• Classes in javax.servlet.http package

The javax.servlet and javax.servlet.http packages represent interfaces and classes for servlet
api.The javax.servlet package contains many interfaces and classes that are used by the servlet or
web container. These are not specific to any protocol.The javax.servlet.http package contains
interfaces and classes that are responsible for http requests only.

Interfaces in javax.servlet package

There are many interfaces in javax.servlet package. They are as follows:

• Servlet
• ServletRequest
• ServletResponse
• RequestDispatcher
• ServletConfig
• ServletContext

Classes in javax.servlet package

There are many classes in javax.servlet package. They are as follows:

• GenericServlet
• ServletInputStream
• ServletOutputStream
• ServletRequestWrapper
• ServletResponseWrapper
• ServletRequestEvent

9
2.2 Web Servers
Web pages are a collection of data, including images, text files, hyperlinks, database files etc., all
located on some computer (also known as server space) on the Internet. A web server is dedicated
software that runs on the server-side. When any user requests their web browser to run any web
page, the webserver places all the data materials together into an organized web page and
forwards them back to the web browser with the help of the Internet.

This intercommunication of a web server with a web browser is done with the help of a
protocol named HTTP (Hypertext Transfer Protocol). These stored web pages mostly use static
content, containing HTML documents, images, style sheets, text files, etc. However, web servers
can serve static as well as dynamic contents. Web Servers also assists in emailing services and
storing files. Therefore it also uses SMTP (Simple Mail Transfer Protocol) and FTP (File
Transfer Protocol) protocols to support the respective services. Web servers are mainly used in
web hosting or hosting the website's data and running web-based applications.

Web server software available in the market

Though there are various web servers found in today's market, but the commonly used one are as
follows:

Apache HTTP Server

This web server is developed by Apache Software Foundation. It is an open-source,


accessible web server available for almost all operating systems, including Windows, MACOS,
Linus, FreeBSD, etc. Apache is one of the most popular web servers used around the globe.

10
2.3 Web Client
A client can be a device or a machine.A client program runs on the local machine,
requesting service from the server. A client program is a finite program means that the service is
started by the user and terminates when the service is completed. For instance, web browser.

A client device is a machine that the end-user uses to access the web. Examples of clients
are smartphones, desktops, laptops, etc.

Web Container

It provides the runtime environment for JavaEE (j2ee) applications. The client/user can
request only a static WebPages from the server. If the user wants to read the web pages as per
input then the servlet container is used in java.

The servlet container is the part of web server which can be run in a separate process. We
can classify the servlet container states in three types:

Servlet Container States

The servlet container is the part of web server which can be run in a separate process. We
can classify the servlet container states in three types:

• Standalone: It is typical Java-based servers in which the servlet container and the web
servers are the integral part of a single program. For example:- Tomcat running by itself
• In-process: It is separated from the web server, because a different program runs within the
address space of the main server as a plug-in. For example:- Tomcat running inside the JBoss.
• Out-of-process: The web server and servlet container are different programs which are run in
a different process. For performing the communications between them, web server uses the
plug-in provided by the servlet container.

The Servlet Container performs many operations that are given below:

o Life Cycle Management


o Multithreaded support
o Object Pooling
o Security etc.
11
2.4 JAVA SERVER PAGES (JSP)
JSP technology is used to create web application just like Servlet technology. It can be
thought of as an extension to Servlet because it provides more functionality than servlet such as
expression language, JSTL, etc.

A JSP page consists of HTML tags and JSP tags. The JSP pages are easier to maintain than
Servlet because we can separate designing and development. It provides some additional features
such as Expression Language, Custom Tags, etc.

Advantages of JSP over Servlet

There are many advantages of JSP over the Servlet. They are as follows:

1) Extension to Servlet

JSP technology is the extension to Servlet technology. We can use all the features of
the Servlet in JSP. In addition to, we can use implicit objects, predefined tags, expression
language and Custom tags in JSP, that makes JSP development easy.

2) Easy to maintain

JSP can be easily managed because we can easily separate our business logic with
presentation logic. In Servlet technology, we mix our business logic with the presentation
logic.

3) Less code than Servlet

In JSP, we can use many tags such as action tags, JSTL, custom tags, etc. that
reduces the code. Moreover, we can use EL, implicit objects, etc.

12
3.BASICS OF HTML

3.1 What is HTML


HTML is an acronym which stands for Hyper Text Markup Language which is used for
creating web pages and web applications. Let's see what is meant by Hypertext Markup
Language, and Web page.

Hyper Text:HyperText simply means "Text within Text." A text has a link within it, is a
hypertext. Whenever you click on a link which brings you to a new webpage, you have clicked
on a hypertext. HyperText is a way to link two or more web pages (HTML documents) with each
other.

Markup language: A markup language is a computer language that is used to apply layout and
formatting conventions to a text document. Markup language makes text more interactiveand
dynamic. It can turn text into images, tables, links, etc.

Web Page: A web page is a document which is commonly written in HTML and translated
by a web browser. A web page can be identified by entering an URL. A Web page can be
of the static or dynamic type. With the help of HTML only, we can create static web
pages.

Hence, HTML is a markup language which is used for creating attractive web pages with thehelp
of styling, and which looks in a nice format on a web browser. An HTML document is made of
many HTML tags and each HTML tag contains different content.

Let's see a simple example of HTML.

1. <!DOCTYPE>
2. <html>
3. <head>
4. <title>Web page title</title>
5. </head>
6. <body>
7. <h1>Write Your First Heading</h1>
8. <p>Write Your First Paragraph.</p>
9. </body>
10. </html>

13
3.2 Description of HTML Example
<!DOCTYPE>: It defines the document type or it instruct the browser about the version of
HTML.

<html > :This tag informs the browser that it is an HTML document. Text between html tag
describes the web document. It is a container for all other elements of HTML except
<!DOCTYPE>

<head>: It should be the first element inside the <html> element, which contains the
metadata(information about the document). It must be closed before the body tag opens.

<title>: As its name suggested, it is used to add title of that HTML page which appears at thetop
of the browser window. It must be placed inside the head tag and should close immediately.
(Optional)

<body>: Text between body tag describes the body content of the page that is visible to theend
user. This tag contains the main content of the HTML document.

<h1> : Text between <h1> tag describes the first level heading of the webpage.

<p>: Text between <p> tag describes the paragraph of the webpage.

3.3 Features of HTML


1) It is very easy to make an effective presentation with HTML because it has a lot of
formatting tags.

2) It is a markup language, so it provides a flexible way to design web pages along with thetext.

3) It facilitates programmers to add a link on the web pages (by html anchor tag), so itenhances
the interest of browsing of the user.

4) It is platform-independent because it can be displayed on any platform like Windows,Linux,


and Macintosh, etc.

5) It facilitates the programmer to add Graphics, Videos, and Sound to the web pages which
makes it more attractive and interactive.

6) HTML is a case-insensitive language, which means we can use tags either in lower-case or
upper-case

14
HTML text Editors
• An HTML file is a text file, so to create an HTML file we can use any text editors.
• Text editors are the programs which allow editing in a written text, hence to create aweb page
we need to write our code in some text editor.
• There are various types of text editors available which you can directly download, butfor a
beginner, the best text editor is Notepad (Windows) or TextEdit (Mac).
• After learning the basics, you can easily use other professional text editors which are,
Notepad++, Sublime Text, Vim, etc.
• In our tutorial, we will use Notepad and sublime text editor. Following are some easyways to
create your first web page with Notepad, and sublime text.

15
4.SQL DATA BASE

4.1 What are the SQL?


SQL follows the following rules:
• Structure query language is not case sensitive. Generally, keywords of SQL are
written in uppercase.

• Statements of SQL are dependent on text lines. We can use a single SQL
statement on one or multiple text line.

• Using the SQL statements, you can perform most of the actions in a database.

• SQL depends on tuple relational calculus and relational algebra

SQL Commands
• SQL commands are instructions. It is used to communicate with the database. Itis also
used to perform specific tassss functionss and queries of data.

• SQL can perform various tasss lise create a tables add data to tabless dropthe
tables modify the tables set permission for users.

16
4.2 Types of SQL Commands
There are five types of SQL commands: DDLs DMLs DCLs TCLs and DQL.

Data Definition Language (DDL)


➢ DDL changes the structure of the table like creating a table, deleting a table, altering
a table, etc.

➢ All the command of DDL are auto-committed that means it permanently


save all the changes in the database.
➢ Here are some commands that come under DDL:
• CREATE
• ALTER
• DROP
• TRUNCATE

Data Definition Language (DDL)- CREATE

CREATE It is used to create a new table in the database.


Syntax:
REATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES]);
17
Example:
CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHA R2(100), DOB
DATE);

Data Definition Language (DDL)- Drop

Drop: It is used to delete both the structure and record stored in the table.

Syntax:
DROP TABLE ;
Example:
DROP TABLE EMPLOYEE

Data Definition Language (DDL)- ALTER


ALTER: It is used to alter the structure of the database. This change could be either to modify the
characteristics of an existing attribute or probably to add a new attribute.

Syntax:
ALTER TABLE table_name ADD column_name COLUMN-definition

Example:
ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20)); ALTER TABLE
STU_DETAILSMODIFY (NAME VARCHAR2(20));

Data Definition Language (DDL)- TRUNCATE


TRUNCATE: It is used to delete all the rows from the table and free the space containing the
table.

Syntax:
TRUNCATE TABLE table_name;

Example:
TRUNCATE TABLE EMPLOYEE;

Data Manipulation Language

DML commands are used to modify the database. It is responsible for all form of CHANGES in
the database.
The command of DML is not auto-committed that means it can't permanently save all the changes
in the database. They can be rollback.

18
Data Manipulation Language - INSERT

INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a
table.
Syntax:
INSERT INTO TABLE_NAME(col1, col2, col3, .... col N)
VALUES (value1, value2, value3, ..... valueN);
OR
INSERT INTO TABLE_NAMEVALUES (value1, value2, value3, .. valueN);

Example:

INSERT INTO XYZ (Author, Subject) VALUES ("Sonoo", "DBMS");

Data Manipulation Language - UPDATE

Update: This command is used to update or modify the value of a column in the table.
Syntax:
UPDATE table_name SET [column_name1= value1,...column_n ameN = valueN]
[WHERE CONDITION]

Example:
UPDATE students
SET User_Name =
'Sonoo' WHERE
Student_Id = '3'

19
Data Control Language
DCL commands are used to GRANT and TAKE BACK authority from any database
user.Here are some commands that come under DCL:
•Grant
•Revoke

Data Control Language - Grant

GRANT: It is used to give user access privileges to a database.

Example:
GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOT HER_USER;

REVOKE: It is used to take back permissions from the user.

Example:

REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;

Transaction Control Language

TCL commands can only use with DML commands like INSERT, DELETE and UPDATE
only.These operations are automatically committed in the database that's why they cannot be used
while creating tables or dropping them.

Here are some commands that come under TCL:


• COMMIT
• ROLLBACK
• SAVEPOINT

Transaction Control Language - COMMIT

Commit: Commit command is used to save all the transactions to the database.
Syntax:
COMMIT;

Example:DELETE FROM CUSTOMERS WHERE AGE = 25; COMMIT ;


20
Data Query Language

DQL is used to fetch the data from the database. It usesonly one command:

SELECT: This is the same as the projection operation of relational algebra. Itis used to select the
attribute based on the condition described by WHERE clause.
Syntax:
SELECT expressions FROM TABLES WHERE conditions;

Example: SELECT emp_name FROM employee WHERE age > 20;

21
5 . HOW JAVA CONNECT WITH DATA BASE

Database Connectivity:

Java Database Connectivity (JDBC) is an application programming interface (API) forthe


programming language Java, which defines how a client may access a database. It is part of the
Java Standard Edition platform, from Oracle Corporation. It provided methods to query and
update data in a database and related towards relational databases. A JDBC-to-ODBC bridge
enables connections to any ODBC-accessible data source in the Java virtual machine (JVM) host
environment.

The JDBC library combines APIs for each of the tasks discussed below
that areassociated with database usage.

o Create a connection to a database.

o Creating SQL or MySQL statements

o Executing SQL or MySQL queries in the database

Viewing & modifying the resulting records. JDBC is a specification that provides a
comprehensive set of interfaces that allows for portable access to anunderlying database.

Java Using JDBC

1. To execute a statement against a database, the following flow is


observed

• Load the driver (Only performed once)

• Obtain a Connection to the database (Save for later use)

• Get a Statement object from the Connection

• Use the Statement object to execute SQL. Updates, inserts and deletes return
Boolean.

22
Selects return a ResultSet

• Navigate ResultSet, using data as required

• Close ResultSet

• Close Statement

2. DO NOT close the connection

• The same connection object can be used to create further statements.

• A Connection may only have one active Statement at a time. Do not forget to close
the statement when it is no longer needed.

• Close the connection when you no longer need to access the database.

3. Using a connection

The Connection interface defines many methods for managing and using a connection
to the

database. Few methods are:

public Statement createStatement( )

public PreparedStatement prepareStatement(String sql)

public void setAutoCommit(boolean)

public void commit( )

public void rollback( )

23
public void close( )

The most commonly used method is createStatement( ).These statements are an updated
statements such as SQL's CREATE, INSERT, UPDATE and DELETE, or they may be query
statements such as SELECT. Statements are termed as a report which is sent to the database
server all time. Prepared Statements are statements which are cached and the execution path is
pre-determined on the database server. When an SQL statement issues against the database, a
Statement object must be created through the Connection.

For example,

//Step 1: Import required packages

import java.sql.*;

public class JdbcCon

// JDBC driver name and database URL

static final String JDBC_DRIVER = "com.sql.jdbc.Driver";

static final String DB_URL = "jdbc:sql://localhost/EMPE";

// Database credentials

static final String UNAME = "username";

static final String UPASS = "password";

public static void main(String[] args)

Connection con = null;

24
Statement stmtt = null;

try

//Step 2: Register JDBC driver

Class.forName("com.mysql.jdbc.Driver");

//Step 3: Open a connection

System.out.println("Connecting to database...");

con = DriverManager.getConnection(DB_URL,UNAME ,UPASS);

//Step 4: Execute a query

System.out.println("Creating statement...");

stmtt = conn.createStatement();

String mysql;

sql = "SELECT id, firstname, lastname, age FROM student";

ResultSet rts = stmtt.executeQuery(sql);

//Step 5: Extract data from result set

while(rts.next())

{
25
//Retrieve by column name

int id = rts.getInt("id");

int age = rts.getInt("yage");

String first = rts.getString("first");

String last = rts.getString("last");

//Display values

System.out.print("ID: " + id);

System.out.print(", YourAge: " + age);

System.out.print(", First: " + firstname);

System.out.println(", Last: " + lastname);

//Step 6: Clean-up environment

rts.close();

stmtt.close();

con.close();

catch(SQLException se)
26
{

//Handle errors for JDBC

se.printStackTrace();

catch(Exception e)

//Handle errors for Class.forName

e.printStackTrace();

Finally

//finally block used to close resources

try

if(stmtt!=null)

stmtt.close();

27
catch(SQLException se2)

{ }// nothing we can do

try{

con.close();

catch(SQLException se)
{

se.printStackTrace();

//end finally try

//end try

System.out.println("Goodbye!");

//end main

28
6.PROGRAMS

Program 1:

import javax.Servlet.*;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet("/log")
public class loginServlet extends HttpServlet{

public void doGet(HttpServletRequest req,HttpServletResponse res) throws


ServletException,IOException
{
String name=req.getParameter("sname");
String pwd=req.getParameter("spwd");
String status="";

res.setContentType("text/html");
PrintWriter out=res.getWriter();

StudentServices ss=new StudentServices();


try
{
String status=ss.checklogin(name,pwd);
}
catch(Exception e)
{
e.printStackTrace();
}
out.println("<html>");
out.println("<body bgcolor='blue'>");
out.println("<center><br><br><br><br>");

if(status.equals("sucess"))
{
out.println("<h2 style='color:red'>Login is Sucessfull</h2>");
}
else
{
out.println("<h2 style='color:red'> Login is Failed");
}
out.println("</center>");
out.println("</body>");
out.println("</html>");

29
public Student getData(String name)throws Exception
{
ResultSet rs=st.executeQuery("select * from student where name=' "+name+"'");
Student s=null;
while(rs.next())
{
s=new Student();
s.setName(rs.getSting("name"));
s.setPwd(rs.getSting("pwd"));
s.setMarks(rs.getSting("marks"));
s.setAddr(rs.getSting("addr"));
s.setMail(rs.getSting("mail"));
s.setMob(rs.getSting("mob"));
}

30
Program 2:

import javax.servlet.*;
import java.io.*;
import java.util.*;
public class FirstServlet implements Servlet
{
static
{
System.out.println("Servlets class is loading");
}
public FirstServlet()
{
System.out.println("obj created or servlets inisitation");
}
public void init(ServletConfig config)
{
System.out.println("init() method is executed");
}
public void Service(ServletRequest req,ServletResponse res);
throws Servletexception,IOException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
pw.println("<h1>WELCOME TO SVEC<\h1>");
}
public ServletConfig getServletConfig()
{
return null;
}
public string getServletInfo()
{
return"This app is developed by ECE Student";
}
public void destory()
{
System.out.println("Destroy() the obj");
}
}
HTML File
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<frameset rows="20%,60%,20%"">
<frame src="header.html"></frame>
<frameset cols="20%,80%'>
<frame src="menu.html"></frame>
<frame src="welcome.html" name="body">
</frameset>
<frame src="footer.html">
31
</frameset>
</html>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body bgcolor="lightblue">
<center><h1>UPDATE STUDENT DETAILS</h1></center>
<form action="update" method="post">
<table algin="center>
<tr>
<td>Student ID</tr></form>
</body>
</html>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<br><br><br><br><br><br><br><br>
<h1>

<marquee>WELCOME TO SERVLET CLASS</marquee>

</body>
</html>

32
Programs 3:

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet("/log")
public class loginServlet extends HttpServlet{

public void doGet(HttpServletRequest req,HttpServletResponse res) throws


ServletException,IOException
{
String name=req.getParameter("sname");
String pwd=req.getParameter("spwd");
String status="";

res.setContentType("text/html");
PrintWriter out=res.getWriter();

StudentServices ss=new StudentServices();


try
{
String status=ss.checklogin(name,pwd);
}
catch(Exception e)
{
e.printStackTrace();
}

out.println("<html>");
out.println("<body bgcolor='blue'>");
out.println("<center><br><br><br><br>");

if(status.equals("sucess"))
{
out.println("<h2 style='color:red'>Login is Sucessfull</h2>");
}
else
{
out.println("<h2 style='color:red'> Login is Failed");
}
out.println("</center>");
out.println("</body>");
out.println("</html>");

33
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="purple">
<center>
<br><br>
<h1 style="color:white" size="7">WELCOME TO SVEC</h1>
</center>

</body>
</html>

34
CONCLUSION

In conclusion, the Java programming language, with its robust features and versatility, remains
a cornerstone in the world of software development. Through this skill- oriented course-IV, I have
gained a comprehensive understanding of Java's fundamentals, object-oriented principles, and its
extensive application in the development of various software solutions. This course has not only
enhanced my proficiency in Java programming but has also equipped me with the ability to design
and implement complex algorithms, create efficient data structures, and develop scalable
applications. The hands-on experience gained through practical exercises and projects has not only
fortified my programming skills but has also instilled in me a deep appreciation for the importance
of clean, well- documented, and maintainable code. Moving forward, I am confident that the
knowledge and expertise acquired during this course will serve as a solid foundation for my future
endeavors in the field of software development. With the in- depth understanding of Java, I am
prepared to contribute effectively to projects that require innovative solutions and advanced
programming techniques. I am eager to apply my skills in real- world scenarios and continue to
explore the ever-evolving landscape of Java development, consistently striving for excellence and
innovation.

35
REFERENCES

1. Freeman, E., & Robson, E. (2019). Head First Java. O'Reilly Media.
• This book provides a beginner-friendly introduction to Java programming,
covering essential concepts and practices for Java development.
2. Walls, C. (2016). Spring in Action. Manning Publications.
• "Spring in Action" is a comprehensive guide to the Spring framework,
including Spring Boot, which is widely used in Java Full Stack
Development for building backend applications.
3. Bauer, C., & King, G. (2006). Java Persistence with Hibernate. Manning
Publications.
• This book offers in-depth insights into Hibernate, an ORM (Object-
Relational Mapping) framework commonly used in Java Full Stack
Development for database interaction.
4. Henney, K., & Evans, B. (2017). Java for Data Science. Packt Publishing.
• "Java for Data Science" explores Java's capabilities in handling data-centric
applications, including database integration and manipulation.
5. D'Agostino, M. (2020). Learning React: A Hands-On Guide to Building Web
Applications Using React and Redux. Addison-Wesley Professional.
• While not specific to Java, this book covers React, a popular frontend
framework often used in Java Full Stack Development for building dynamic
user interfaces.
6. Wright, J., & Charlie, S. (2017). MySQL 8 Cookbook: Over 150 recipes for high-
performance database querying and administration. Packt Publishing.
• "MySQL 8 Cookbook" offers practical recipes and techniques for working
with MySQL databases, which are commonly used in Java Full Stack
Development projects.
7. Freeman, E., & Freeman, E. (2018). Head First Design Patterns. O'Reilly Media.
• This book introduces design patterns, including those relevant to Java Full
Stack Development, which can help in architecting robust and scalable
applications.

36

You might also like