0% found this document useful (0 votes)
67 views15 pages

Advanced Java:: Archi by Distributing Multiple Machines)

The document discusses advanced Java topics including JDBC, servlets, JSP, databases, application types, user interfaces, applets, and distributed applications. It explains that JDBC is used to connect Java applications to databases, servlets and JSP are used to create dynamic web content, and there are two types of Java applications: standalone and distributed. Distributed applications can be either web-based or remote, requiring JVMs on both client and server machines.

Uploaded by

Ajay Karuppusamy
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)
67 views15 pages

Advanced Java:: Archi by Distributing Multiple Machines)

The document discusses advanced Java topics including JDBC, servlets, JSP, databases, application types, user interfaces, applets, and distributed applications. It explains that JDBC is used to connect Java applications to databases, servlets and JSP are used to create dynamic web content, and there are two types of Java applications: standalone and distributed. Distributed applications can be either web-based or remote, requiring JVMs on both client and server machines.

Uploaded by

Ajay Karuppusamy
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/ 15

ADVANCED JAVA:

1.JDBC

2.SERVLETS(WEB TECHNOLOGY)

3.JSP(WT)

AND PHP(WT),CGI(WT),PERL(WT)(NOT IN AD JAVA)

FOR DATABASE:

1.ORACLE

2.MYSQL

THERE ARE TWO TYPES OF APPLICATION IN JAVA:

1.STANDALONE AND 2.ENTERPRISE / DISTRIBUTED APPS(THE DESIGN OF APP HAS CLIENT-SERVER


ARCHI BY DISTRIBUTING MULTIPLE MACHINES)

1.THE TYPES ARE

I)CUI-CHARACTER USER INTERFACE IT IS LIKE CONSOLE

II)GUI-GRAPHICAL USER INTERFACE IT IS LIKE A NEW WINDOW APPREARS IN SCREEN AND WE HAVE
TO INPUT VALUES IN THAT

CUI and GUI are user interface used in connection with computers. • CUI is the precursor
of GUI and stands for character user interface where user has to type on keyboard to
proceed. On the other hand GUI stands for Graphical User Interface which makes it
possible to use a mouse instead of keyboard
An applet is a program written in the Java programming
language that can be included in an HTML page, much in the same way
an image is included in a page. When you use a Java
technology-enabled browser to view a page that contains an applet,
the applet's code is transferred to your system and executed by the
browser's Java Virtual Machine (JVM). 
Applets are Java programs which are capable of being run
within a browser. Swing is a GUI framework.
2. Applet belongs to java.awt package and swing belongs to
javax.swing.* package.
3. Applet is a heavy weight component but swing comes under
light weight component's category.
2.ENTERPRISE OR DISTRIBUTED APPS:

I)WEB APPS OR WEB BASED DISTRIBUTED APP


APPLICATION LOGIC IS TOTALLY IMPLEMENTED IN SERVER MACHINE BUT NOT IN CLIENT MACHINE

JVM IS REQUIRED BY SERVER MACHINE BCZ IT HAS JAVA CODE.

JVM IS AVAILABLE IN WEB CONTAINER(SERVLETS,JSP) AND CONTAINER IS AT SERVER MACHINE

Web PAGE ONLY UNDERSTAND SCRIPTING LANGUAGE BUT


NOT JAVA SO INORDER TO ACHIEVE VARIOUS FUNCTIONS
AND STYLLING FEATURES IN WEB PAGES HTML AND CSS ARE
USED .THEN THE REQUEST SENT BY THE USER IS RECEIVED BY
THE SERVER WHICH UNDERSTANDS JAVA AND MANIPULATES
THE DATA FROM DATABASE.EVENTUALLY SENDS THE
RETURN REQUEST TO THE WEB PAGE.
CAN BE EXECUTED BY TWO SERVERS

I)WEB SERVER(EXECUTE WEB APPS)

II)APP SERVER(EXECUTE BOTH WEB APPS AND D”APPS)

->THE MAIN PURPOSE OF THIS TO GENERATE DYNAMIC RESPONSE FROM RECEIVED STATIC
RESPONSE.

II)DISTRIBUTED OR REMOTE BASED DIS APP(NOT WITH BROWSER)


APPLICATION LOGIC IS DISTRIBUTED OVER CLIENT AND SERVER MACHINES.

JVM’S ARE REQUIRED AT BOTH CLIENT AND SERVER.

THIS IS EXECUTED BY ONLY APP SERVER.BCZ APP SERVER HAS THE MIDDLE WARE
SERVICES(JAAS,JNDI,JTA).

EG:APPLET,GUI

TECHNOLOGIES FOR D APPS: SOCKET PRG,RMI,CORBA,EJBs,WEBSERVICES(but it is not web


technology)

->THIS IS TO ESTABLISH COMMUNICATION BET LOCAL MACHINE AND REMOTE MACHINE INORDER
TO GET REMOTE SERVICES FROM REMOTE MACHINES.
NOTE : ON COMBINING THE ARROW POINTS CONSIDER
PLACING ORDER IN AMAZON AND PAYING AMOUNT
THROUGH THE BANK SERVER.
THE MAIN INTENTION OF SERVLET AND JSP IS TO
DESIGN A WEB APPLICATION TO GENERATE DYNAMIC
RESPONSE FROM SERVER MACHINE.
TWO TYPES OF RESPONSE:
1.STATIC
NOT GENERATING A RESPONSE FROM SERVER
EG: CONSIDER FB WHEN 100 PEOPLE ARE ENTERING LOGIN PAGE IT JUST
SHOWS UP THE PAGE WITHOUT ANY SERVER MACHINE help. (.html files)
2.DYNAMIC
GENERATING A RESPONSE FROM SERVER(by the WEB APP AND THIS IS DEVELOPED BY WEB
TECHNOLOGIES)

Eg:in the same eg when we are typing our own mail id and password then it
has some server machine operations .
NOTE: WHY WE ARE GOING TO SERVLETS WHILE CGI(COMMON GATEWAY
INTERFACE ) IS AVAILABLE?
TO ANS THIS,CGI IS DESIGNED BY C PRG LANG SO IT IS PROCESS BASED
PRGMING.WHEN MULTIPLE REQUEST ARE SENT TO SERVER IT CREATES
SEPARATE PROCESS TO EXECUTE IT ,IT IS HEAVY WEIGHT(CONSUMES MORE
MEMORY )
AND THE EXE TIME IS LONG FINALLY ITS EFFICIENCY REDUCES.
SERVLET IS JUST OPPOSITE TO THE CGI,IT CREATES THREAD FOR EVERY
REQUEST ,TAKES LESS MEMORY AND LESS TIME.
DIFFERENCE BETWEEN JSP(JAVA SERVER PAGE) AND SERVLET:
IF WE KNOW JAVA BASICS WE CAN USE SERVLET
ELSE IF WE DON’T KNOW JAVA WE CAN USE JSP(SCRIPTING LANGUAGE CAN BE
EASILY UNDERSTANDABLE).
BUT ONLY JSP IS NOT REQUIRED TO BUILD WEB APPS.
WHERE TO USE SERVLET(USED IN PROCESSING):TO TAKE REQUEST FROM
CLIENT AND PROCESS(BUSINESS LOGIC) IT.
AND JSP(USED IN PRESENTATION):TO GENERATE DYNAMIC RESPONSE WITH
VERY GOOD LOOK AND FEEL.
EG:CONSIDER LOGIN PAGE ,USERNAME AND PASS ARE PROCESSED BY SERVLET
AND THEN THE STATUS OF LOGIN SUCCESSFUL OR FAILURE IS PRESENTED BY
JSP.
IF WE USE ONLY SERVLET THEN WE CANNOT PRESENTATION AND BUSINESS
LOGIC.
IF WE USE ONLY JSP THEN WE CAN SEPARATE BOTH LOGICS BCZ IT HAS HTML
TAGS AND JSP TAGS FOR BUSINESS LOGIC.

MVC:MODULAR VIEW CONTROL


SINGLE SERVLET IS USED AS CONTROLLER
SET OF JSP PAGES AS VIEW PART
FRAME WORKS:
1.STRUCTS
2.JSF
3.SPRING MVC
IN NETBEANS THE XML (EXTENSIBLE MARKUP LANGUAGE ) IS WIHTIN THE
INSTALLER SETUP OR ELSE WE HAVE TO INSTALL SEPARATELY.THE USE OF XML
ARE,
1. Web. xml file is the configuration file of web applications in java.
2. It instructs the servlet container which classes to load, what parameters to set
in the context, and how to intercept requests coming from browsers.
3. Web. xml is called as deployment descriptor file.
4. use web.xml in servlet.

JDBC Drivers
Java Database Connectivity (JDBC) is an application programming interface (API)
for the programming language Java, which defines how a client may access any kind
of tabular data, especially relational database. It is part of Java Standard Edition
platform, from Oracle Corporation. It acts as a middle layer interface between java
applications and database.
The JDBC classes are contained in the Java Package java.sql and javax.sql.
JDBC helps you to write Java applications that manage these three programming
activities:
1. Connect to a data source, like a database.
2. Send queries and update statements to the database
3. Retrieve and process the results received from the database in answer to your query
Structure of JDBC 

Why Should We Use JDBC


Before JDBC, ODBC API was the database API to connect and execute the query with the
database. But, ODBC API uses ODBC driver which is written in C language (i.e. platform
dependent and unsecured). That is why Java has defined its own API (JDBC API) that
uses JDBC drivers (written in Java language).
We can use JDBC API to handle database using Java program and can perform the
following activities:

1. Connect to the database


2. Execute queries and update statements to the database
3. Retrieve the result received from the database.

Do You Know
o How to connect Java application with Oracle and Mysql database using JDBC?
o What is the difference between Statement and PreparedStatement interface?
o How to print total numbers of tables and views of a database using JDBC?
o How to store and retrieve images from Oracle database using JDBC?
o How to store and retrieve files from Oracle database using JDBC?

What is API
https://www.tutorialspoint.com/jdbc/index.htm

API (Application programming interface) is a document that contains a description of all


the features of a product or software. It represents classes and interfaces that software
programs can follow to communicate with each other. An API can be created for
applications, libraries, operating systems, etc.

JDBC Driver is a software component that enables java application to interact with the
database. There are 4 types of JDBC drivers:
1. JDBC-ODBC bridge driver
2. Native-API driver (partially java driver)
3. Network Protocol driver (fully java driver)
4. Thin driver (fully java driver)

1) JDBC-ODBC bridge driver


The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge
method calls into the ODBC function calls. This is now discouraged because of thin driver.
In Java 8, the JDBC-ODBC Bridge has been removed.

Oracle does not support the JDBC-ODBC Bridge from Java 8. Oracle recommends that
you use JDBC drivers provided by the vendor of your database instead of the JDBC-
ODBC Bridge.

Advantages:
o easy to use.
o can be easily connected to any database.

Disadvantages:
o Performance degraded because JDBC method call is converted into the ODBC
function calls.
o The ODBC driver needs to be installed on the client machine.

2) Native-API driver
The Native API driver uses the client-side libraries of the database. The driver converts JDBC method
the database API. It is not written entirely in java.
Advantage:
o performance upgraded than JDBC-ODBC bridge driver.

Disadvantage:
o The Native driver needs to be installed on the each client machine.
o The Vendor client library needs to be installed on client machine.

next →← prev

JDBC Driver
1. JDBC Drivers
1. JDBC-ODBC bridge driver
2. Native-API driver
3. Network Protocol driver
4. Thin driver

JDBC Driver is a software component that enables java application to interact with the database.
drivers:
1. JDBC-ODBC bridge driver
2. Native-API driver (partially java driver)
3. Network Protocol driver (fully java driver)
4. Thin driver (fully java driver)
1) JDBC-ODBC bridge driver
The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC brid
method calls into the ODBC function calls. This is now discouraged because of thin driver.

In Java 8, the JDBC-ODBC Bridge has been removed.

Oracle does not support the JDBC-ODBC Bridge from Java 8. Oracle recommends that you use JDBC
vendor of your database instead of the JDBC-ODBC Bridge.

Advantages:
o easy to use.
o can be easily connected to any database.

Disadvantages:
o Performance degraded because JDBC method call is converted into the ODBC function calls.
o The ODBC driver needs to be installed on the client machine.

2) Native-API driver
The Native API driver uses the client-side libraries of the database. The driver converts JDBC meth
the database API. It is not written entirely in java.
Advantage:
o performance upgraded than JDBC-ODBC bridge driver.

Disadvantage:
o The Native driver needs to be installed on the each client machine.
o The Vendor client library needs to be installed on client machine.

3) Network Protocol driver

The Network Protocol driver uses middleware (application server) that converts JDBC calls directly or
specific database protocol. It is fully written in java.
Advantage:
o No client side library is required because of application server that can perform many tasks lik
logging etc.

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

4) Thin driver
The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it
It is fully written in Java language.
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.

Java Database Connectivity with 5 Steps


There are 5 steps to connect any java application with the database using JDBC. These steps are as f

o Register the Driver class


o Create connection
o Create statement
o Execute queries
o Close connection
1) Register the driver class
The forName() method of Class class is used to register the driver class. This method is used to dyn
class.

Syntax of forName() method


1. public static void forName(String className)throws ClassNotFoundException  

Note: Since JDBC 4.0, explicitly registering the driver is optional. We just need to
put vender's Jar in the classpath, and then JDBC driver manager can detect and
load the driver automatically.

Example to register the OracleDriver class


Here, Java program is loading oracle driver to esteblish database connection.

1. Class.forName("oracle.jdbc.driver.OracleDriver");  

2) Create the connection object


The getConnection() method of DriverManager class is used to establish connection with the datab

Syntax of getConnection() method


1. 1) public static Connection getConnection(String url)throws SQLException  
2. 2) public static Connection getConnection(String url,String name,String passwor
d)  
3. throws SQLException  

Example to establish connection with the Oracle


database
1. Connection con=DriverManager.getConnection(  
2. "jdbc:oracle:thin:@localhost:1521:xe","system","password");  

3) Create the Statement object


The createStatement() method of Connection interface is used to create statement. The object of sta
execute queries with the database.

Syntax of createStatement() method


1. public Statement createStatement()throws SQLException  

Example to create the statement object


1. Statement stmt=con.createStatement();  

4) Execute the query


The executeQuery() method of Statement interface is used to execute queries to the database. This
object of ResultSet that can be used to get all the records of a table.

Syntax of executeQuery() method


1. public ResultSet executeQuery(String sql)throws SQLException  

Example to execute query


1. ResultSet rs=stmt.executeQuery("select * from emp");  
2.   
3. while(rs.next()){  
4. System.out.println(rs.getInt(1)+" "+rs.getString(2));  
5. }  

5) Close the connection object


By closing connection object statement and ResultSet will be closed automatically. The close() metho
interface is used to close the connection.

Syntax of close() method


1. public void close()throws SQLException  

Example to close connection


1. con.close();  
Note: Since Java 7, JDBC has ability to use try-with-resources statement to
automatically close resources of type Connection, ResultSet, and Statement.

It avoids explicit connection closing step.

TO KNOW HOW TO CONNECT MYSQL DATABASE USING JDBC SEE THIS VIDEO:
https://www.youtube.com/watch?v=yeefScqwi0g

You might also like