Professional Documents
Culture Documents
1
Fall-Semester 2022-2023 Dr. A Justin Gopinath SCOPE
CSI3018- Advanced Java
Syllabus
Module:1 JDBC Programming 4 hours
JDBC Architecture, Creating simple JDBC Application, Statements, ResultSet Operations, Batch
Updates in JDBC, Creating CRUD Application, Using Rowsets Objects, Managing Database
Transaction.
Module:2 Servlet API and JSP – Overview 4 hours
Servlet Introduction, Working with Servlet Context and Servlet Config Objects, Response and
Redirection, Filter API, Hidden Form Fields and URL Rewriting, Servlet Events – Context Level and
Session Level. JSP Architecture, JSP Scripting Elements, JSP Directives, JSP Action, JSP Implicit
Objects, JSP Standard Tag Libraries, JSP Custom Tag
Module:3 J2EE and Web Development 4 hours
Java Platform, J2EE Architecture Types, Java EE Containers, Servers in J2EE Application, Web
Application Structure, Web Containers and Web Architecture Models. Request Processing in Web
Application.
Module:4 Advance Networking 4 hours
Introduction of Socket, Types of Socket, Socket API, TCP/IP client sockets, URL,
TCP/IP server sockets, Datagrams, java.net package Socket, ServerSocket, InetAddress,
URLConnection, RMI Architecture, Client Server Application using RMI
2
SCOPE
CSI3018- Advanced Java
Syllabus
Module:5 Hibernate 4 hours
Introduction to Hibernate, Exploring Architecture of Hibernate, O/R Mapping with Hibernate,
Hibernate Annotation, Hibernate Query Language, CRUD Operation using Hibernate API.
3
SCOPE
CSI3018- Advanced Java
Syllabus
Text Books
1.Core and Advanced Java, Black Book, Recommended by CDAC, Revised and Upgraded by
Dreamtech Press, 2018
2.Richard M Reese, Learning Network Programming with Java, Packt publisher, 2015
Reference Books
1.Craig walls ,Spring in Action, 5th edition, Manning Publication,2020.
2.Pankaj B. Brahmankar, Advanced JAVA Programming, Tech Neo Publications, 2019.
4
SCOPE
CSI3018- Advanced Java
5
SCOPE
CSI3018- Advanced Java
6
SCOPE
CSI3018- Advanced Java
Module–I
JDBC Programming
7
SCOPE
CSI3018- Advanced Java
Write a Java program for creating one base class for student personal details
and inherit those details into the sub class of student Educational details
(UGStudent, PGStudent) to display complete student information
8
SCOPE
CSI3018- Advanced Java
Assessment - 1
Install and configure NetBeans IDE for developing web
application in your local machine
9
SCOPE
CSI3018- Advanced Java
JDBC Connectivity
• JDBC is: Java DataBase Connectivity
– is a Java API for connecting programs written in Java to the data in
relational databases.
– consists of a set of classes and interfaces written in the Java programming
language.
– provides a standard API for tool/database developers and makes it possible
to write database applications using a pure Java API.
• JDBC:
– establishes a connection with a database
– sends SQL statements
– processes the results.
10
SCOPE
CSI3018- Advanced Java
JDBC API
• The JDBC API supports both two-tier and three-tier models for
database access.
• Two-tier model -- a Java applet or application interacts directly with
the database.
• Three-tier model -- introduces a middle-level server for execution of
business logic:
– the middle tier to maintain control over data access.
– the user can employ an easy-to-use higher-level API which is
translated by the middle tier into the appropriate low-level calls.
11
SCOPE
CSI3018- Advanced Java
JDBC Architecture
Java Application
Native driver
ODBC Driver
(DBMS specific)
DBMS 12
SCOPE
CSI3018- Advanced Java
JDBC Steps
1. Importing Packages
2. Registering the JDBC Drivers
3. Opening a Connection to a Database
4. Creating a Statement Object
5. Executing a Query and Returning a Result Set
Object
6. Processing the Result Set
7. Closing the Connection
13
SCOPE
JDBC API 4.0 mainly provides 2 important packages:
CSI3018- Advanced Java
•java.sql
•javax.sql
1: Importing Packages
JDBC API 4.0 mainly provides 2 important packages:
i) java.sql - package provides classes and interfaces to perform most
of the JDBC functions like creating and executing SQL queries
ii) javax.sql - a JDBC extension API and provides server-side data
access and processing in Java Program.
//Import packages
import java.sql.*; //JDBC packages
import java.math.*;
import java.io.*;
14
SCOPE
CSI3018- Advanced Java
MySQL com.mysql.jdbc.Driver
Oracle oracle.jdbc.driver.OracleDriver
MS Access net.ucanaccess.jdbc.UcanaccessDriver
15
SCOPE
CSI3018- Advanced Java
Types of Drivers:
1. JDBC-ODBC bridge driver - any database. performance degraded
2. Native-API driver (partially java driver) - Native API driver uses the client-
side libraries of the database, Native driver needs to be installed on the each
client machine
3. Network Protocol driver (fully java driver) – uses middleware (application
server) that converts JDBC calls directly or indirectly into the vendor-specific
database protocol
4. Thin driver (fully java driver) - converts JDBC calls directly into the vendor-
specific database protocol. Better performance than all other drivers
16
SCOPE
CSI3018- Advanced Java
Public static void registerDriver(driver) – This method will register the driver with the Driver
Manager. If the driver is already registered, then it won’t take any action.
It will throw SQLException if the database error occurs.
It will throw NullPointerException if the driver is null.
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver())
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver())
17
SCOPE
CSI3018- Advanced Java
Oracle jdbc:oracle:thin:@HOST_NAME:PORT:SERVICE_NAME
Example:
Connection con =
DriverManager.getConnection(jdbc:oracle:thin:@localhost:1521:xe,System,Pass123@)
18
SCOPE
CSI3018- Advanced Java
5. Executing a Query
There are 4 important methods to execute the query in Statement interface
1. ResultSetexecuteQuery(String sql) - used to execute the SQL query and retrieve the values
from DB
2. int executeUpdate(String sql) - used to execute value specified queries like INSERT, UPDATE,
DELETE (DML statements)
3. Boolean execute(String sql) - used to execute the SQL query. It returns true if it executes the
SELECT query. And, it returns false if it executes INSERT or UPDATE query
4. int []executeBatch() - to execute a batch of SQL queries to the Database and if all the queries
get executed successfully, it returns an array of update counts.
Example:
20
SCOPE
CSI3018- Advanced Java
the queries using the executeQuery() method, the result will be stored in the ResultSet
object.
ResultSet rs1= statemnt1.executeQuery(QUERY));
A ResultSet object points to the current row in the Resultset. To iterate the data in the
ResultSet object, call the next() method in a while loop.
If there is no more record to read, it will return FALSE.
21
SCOPE
CSI3018- Advanced Java
conn.close();
22
SCOPE
CSI3018- Advanced Java
JDBC Program
import java.sql.*;
public class JDBCDemo {
public static void main(String[] args) {
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/demo","root",“password");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" ");
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
23
SCOPE
CSI3018- Advanced Java
Or if you are using MySQL Command Line Client program, save the above script into a file, let’s say,
SQLScript.sqland execute the following command:
24
source Path\To\The\Script\File\SQLScript.sql SCOPE
CSI3018- Advanced Java
int count = 0;
while (result.next()){
String name = result.getString(2);
String pass = result.getString(3);
String fullname = result.getString("fullname");
String email = result.getString("email");
26
SCOPE
CSI3018- Advanced Java
27
SCOPE
CSI3018- Advanced Java
28
SCOPE
CSI3018- Advanced Java
JDBC Transaction
32
SCOPE
CSI3018- Advanced Java
} finally {
// close statements
connection.setAutoCommit(true);
} 33
SCOPE
CSI3018- Advanced Java
connection.setAutoCommit(false);
By default, a new connection is in auto-commit mode. each SQL statement is treated as a
transaction and is automatically committed right after it is executed. So we have to disable the auto
commit mode to enable two or more statements to be grouped into a transaction.
connection.commit();
all subsequent SQL statements are included in the current transaction, and they are committed as a
single unit until we call the method commit()
connection.rollback();
If any statement failed to execute, a SQLException is thrown, and in the catch block, we invoke the
method rollback() to abort the transaction
34
SCOPE
CSI3018- Advanced Java
Thank you
36
SCOPE