Advance Java Notes
Advance Java Notes
ADVANCE JAVA
==> It is used to create a complete application.
APPLICATION
The collection of programs is known as application.
2. Web Application
3. Mobile Application
4. Distributed Application
==> The application which will work without internet is known as Stand Alone
Application.
==> Stand Alone Applications are present in Client Machine (User System).
------------------------------------------------------------------------------------------------
NOTE:
Stand Alone Applications are known as Independent Applications.
------------------------------------------------------------------------------------------------
2.) WEB APPLICATION
==> The application which will work with internet and browser is known as
Web Application.
==> To develop Web Application we require Web Technology and Advance
Java.
------------------------------------------------------------------------------------------------
NOTE:
==> Browser is an application which is used to access Web Applications
by using Internet.
------------------------------------------------------------------------------------------------
COMPONENTS OF WEB APPLICATIONS
1. Front-End
2. Back-End
1. FRONTEND
==> The elements which are visible to the user is known as Front-End of an
application.
2. BACKEND
==> The elements which are not visible to the user is known as Back-End of an
application.
==> The application which contains only Front-End is known as Static Web
Application.
SERVER
==> User is using the server access Web Applications by sending Request and
Response.
DATE : 09-08-2022
3.) Mobile Application
==> The Application which needs to download and install in Mobile is known
as Mobile Application
Example: Google(Gmail,GMap,GDrive,GPhotos,Youtube),
Amazon(AmazonPay,Prime,Music,Shopping)
PROGRAM
package demo;
Sequential Numbers
==> The numbers which are present one after the another (or) one-by-one is
known as Sequential Numbers.
Example:
Random Numbers
package demo;
import java.util.Random;
64
DATE : 10-08-2022
GENERATION OF OTP
Q. WAP TO GENERATE 4 DIGITS OTP
package demo;
import java.util.Random;
package demo;
import java.util.Random;
package demo;
import java.util.Random;
import java.util.Scanner;
==> Random Class is one of the Inbuilt class which is present in java.util
package.
==> nextInt() method can be called by using Random class reference variable.
==> Scanner class nextInt() method is used to read the Integer values in
RunTime.
System.err.println();
1. Commercial Application
2. Organizational Application
1. Commercial Application
2. Organizational Application
Example: 1. com.google.gmail
2. org.jspiders.hr
------------------------------------------------------------------------------------------------
NOTE:
==> ‘.’ is used to create a folder inside a folder
------------------------------------------------------------------------------------------------
DATE : 12-08-2022
JAR FILE
==> JAR file stands for “Java ARchive”.
==> ZIP files are used to share large data files with one person to another
person.
==> The process of sharing java programs from one developer to another
developer by converting as JAR file is known as Communication Medium.
==> JAR files are used to provide a security for Java Programs. Because JAR
files cannot be modifiable.
==> JAR files are used to share Java programs from one developer to another
developer.
1. Source folder
2. Bin folder
==> JAR file will contain only Class files(Developer can only execute).
Project
DATE : 15-08-2022
TYPES OF LIBRARIES
2. Referenced Libraries
==> All predefined packages and classes are present in JRE System Library.
2. Referenced Libraries
==> After creation of Java file we are using Complier to create Class file.
==> Project can contain two types of files, Source file as well as Class file.
==> After converting the project into JAR file, JAR file will not contain Source
code to read a code. So we need to go with De-Compiler.
==> De-Compiler is used to convert Class file into Source file for readability
purpose.
Source code
DATE : 16-08-2022
PERSPECTIVE
==> Perspectives are used to decide which type of application we are
developing.
1. Java Perspective
2. JavaEE perspective
1. Java Perspective
==> Java Perspective is used to develop the application which will work
without internet (Standalone Application).
2. JavaEE Perspective
==> JavaEE Perspective is used to develop the application which will work
with internet (Web Application).
Folder
==> Open Eclipse Click the window Right side of ‘Quick access’
==> Help Install new softwares Drag the ‘Work with’ tagbar
------------------------------------------------------------------------------------------------
NOTE:
==> JavaEE stands for ‘Java Enterprise Edition’.
==> Advance Java can be called as JEE / J2EE.
------------------------------------------------------------------------------------------------
DATE : 17-08-2022
(API) APPLICATION PROGRAMMING INTERFACE
==> API is used to share the information from one application to another
application.
==> API is a mediator between two applications.
==> The process of sharing the information from one application with another
application technically referred as Communication Medium.
------------------------------------------------------------------------------------------------
NOTE:
==> The API terminology is present in JavaEE Perspective.
------------------------------------------------------------------------------------------------
FOLDER
Package API
==> The collection of non-static, abstract, static and final variables is known as
Interface.
DRIVERS
==> Drivers are nothing but Translators.
==> Drivers are used to convert one type of language into another type of
language.
==> The process of converting one type of language into another type of
language is known as Translation.
Examples:
DATE : 18-08-2022
JDBC ARCHITECTURE
==> JDBC stands for “Java DataBase Connectivity”
==> The application which we are using to collect the user information it cannot
be stored the data by itself. So we need to go with Database.
==> To understand the process of JDBC Architecture we have to follow major
four components.
1. Java Application
2. JDBC API
3. JDBC Drivers
4. Database
1. Java Application
==> The data which is collected by the Java application we have to store it in
database.
==> We can collect the data by the Java application in two ways.
2. JDBC API
==> JDBC API is used to sharing the user information from Java application to
Database application.
==> Classes and Interfaces which are present in JDBC API (java.sql package).
2. Connection
3. Statement
5. Callable Statement
6. Result Set
3. JDBC DRIVERS
==> JDBC Drivers are used to convert Java information into SQL information
(or) Java Language into SQL language (or) Java Calls into SQL Calls
------------------------------------------------------------------------------------------------
NOTE:
The data which is collected in Java application is present in Java
language, Java language cannot be understandable by Database, It is understand
only Query language, So to make Database to understand Java instruction we
need to convert into SQL instruction, So we make use of JDBC drivers.
------------------------------------------------------------------------------------------------
4. DATABASE
1. Oracle
2. MySQL
==> To get the RDBMS in system and working with MySQL we have to install
SQLyog Application.
1. Create
3. Update
4. Delete
DATE : 19-08-2022
WORKING WITH SQLYOG APPLICATION
7. Scale (or) Precision are mandatory when we are using “double” datatype.
STEPS TO CREATE TABLE INSIDE DATABASE
1. Select the Database and Right click on it.
2. Select an option called as “Create Table”.
3. Specify the field values by providing datatype, fieldname, length, primary
key, NOT NULL values.
4. After the field values click on “Create Table”.
5. Specify the table name and click on Finish.
6. We will get a message as “Table created successfully”.
DATE : 22-08-2022
==> On the database we can perform two operations.
1. Read operation
2. Write operation
==> To perform write operation we are using insert, update, delete queries
==> To perform read operation we are using select query.
==> To alter the table
Select Table Right click Alter table option
==> Primary key value which is used to allow unique values in the specific
columns.
==> NOT NULL is used to doesn’t allow NULL values in the specific column.
==> After creating the table user can see his data by setting “View data”.
STEPS TO VIEW DATA
Select Table Right click Select View Data option
==> To see the modification on the database for values we have to keep on
refreshing the table.
SYNTAX FOR SELECT QUERY WITH EXAMPLE
SELECT */COLUMN_NAME
FROM DATABASE_NAME.TABLE_NAME
WHERE <CONDITION>;
Eg: select * from teja15.employee where deptNo=10;
DATE : 23-08-2022
Q. CREATE A CAR TABLE WHICH CONTAINS 5 COLUMNS
DATE : 24-08-2022
URL
==> URL stands for ‘Uniform Resource Locator’.
==> URL helps to the API to share the information from one application to
another application.
==> It is mandatory to use URL to connect with Java application and Database
application.
==> Every database will contain four information.
1. PROTOCOL
==> User information are storing inside database because we need to connect
with database.
1. Oracle 2. MySql
==> To give more clarity about the URL we have to use Sub-protocol.
1. Local Host
2. Remote Host
1. Local Host
==> If an application is present inside user system then we are going to use
Local host.
2. Remote Host
==> If an application is present inside server we are going to use Remote host.
==> To store the user data inside database first we need to get in, for that we
have to open the gateway by using port number.
==> For a MySQL server, there are two port numbers 3306 and 3307
4. USER INFORMATION
==> All the applications are already present with basic security by port number.
To increase more security we make use of user information.
==> The combination of protocol, host information, port number, user
information is known as URL
For Example 1,
If programmer is using MySQL database the protocol is “jdbc : mysql” and host
information is “localhost” ( Because SQLyog application is present in the user
system) and port number will be “3306 (or) 3307” and the username for
MySQL database is “root” and password is “12345”.
For Example 2,
If programmer is using Oracle database the protocol is “jdbc : oracle” and host
information is “localhost” and the port number of oracle database is “1521” and
the username is “SCOTT” and password is “TIGER”.
==> Without using inbuilt code if we develop an application it will take more
time.
==> With using inbuilt code if we develop an application it will take less time.
==> All the developers will always prefer to go with using inbuilt code.
STEPS
1. Establishing Connection
2. Create a Platform
3. Execution of Query
4. Process of Resultant data
5. Close Connection
Q.
void addStudent();
void removeStudent();
void searchStudent();
void deleteStudent();
}
package org.jsp.jdbc;
College c1 = Department.getCollege();
c1.addStudent();
c1.searchStudent();
c1.removeStudent();
c1.deleteStudent();
}
}
OUTPUT
==>To pass the query from Java application to Database application we have to
establish a connection first.
Interface
package org.jsp.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
try
{
Connection c = DriverManager.getConnection(url);
System.out.println("Connection Established
Successfully...!");
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
==> Platforms are used to carry the query from Java application to Database
application.
==> Java application contains both Java code as well as SQL code.
==> To make SQL query to understand the compiler we make use of Platforms.
TYPES OF PLATFORMS
1. Statement Platform
2. PrepareStatement Platform
3. CallableStatement Platform
==> The SQL queries which are present in Java program can understandable by
Database.
NOTE :
The main use of platform is to carry the query from Java application to
Database application.
------------------------------------------------------------------------------------------------
HARDCODED VALUE
==> The value which is entered by the Developer is known as Hardcoded value.
RUNTIME VALUE
==> The value which is entered by the User is known as Runtime value.
PLATFORMS
Connection(I) createStatement( )
Non-static Statement(I)
Return type
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
try
{
Connection connection =
DriverManager.getConnection(url);
Statement stmt = connection.createStatement();
System.out.println("Platform Created...!");
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Platform Created...!
3. EXECUTION OF QUERY
package org.jsp.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
Connection Established...!
Platform Created...!
Query Executed...!
DATE : 01-09-2022
4. PROCESS OF RESULTANT DATA
==> It is an optional step in JDBC because resultant data will not be created for
all the queries, it creates only for select query.
------------------------------------------------------------------------------------------------
NOTE:
==> The data which is present in the database is known as Actual data.
==> The query after reaching to the database there are three operations will get
performed.
1. Compilation of query
2. Execution of query
==> The data which is present in the Buffer memory is known as Resultant
data.
==> Resultant data is temporary data.
------------------------------------------------------------------------------------------------
BUFFER MEMORY
==> Buffer memory will get created after performing the read operation.
------------------------------------------------------------------------------------------------
NOTE:
------------------------------------------------------------------------------------------------
RESULT SET
==> ResultSet is an interface which is present in java.sql package
1. next( ) boolean
2. last( ) boolean
3. beforeFirst( ) void
4. getter getInt(column_number,column_name)
getString(column_number,column_name)
getDouble(column_number,column_name)
getFloat(column_number,column_name)
1. next( )
==> It is used to move the cursor from one record to another record, return type
is boolean.
2. last( )
==> It is used to move the cursor to the last record which is present oin Buffer
memory, return type is boolean.
3. beforeFirst( )
==> It is used to move the cursor from current record to BFR pointer, return
type is void.
4. getter methods
==> They are used to get the data from the Buffer memory based on column
data-type.
==> Getter methods are overloaded methods, we can pass any value as follows.
1. Column_number
2. Column_name
package org.jsp.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
String query = "select * from teja15.employee where empId=105";
try
{
Connection connection =
DriverManager.getConnection(url);
System.out.println("Connection Established...!!!");
Statement stmt = connection.createStatement();
System.out.println("Platform Created");
ResultSet rs = stmt.executeQuery(query);
if(rs.next())
{
System.out.println("Valid Employee ID.....");
System.out.println("***************");
int id = rs.getInt("empId");
String name = rs.getString("empName");
double sal = rs.getDouble("empSal");
int dept = rs.getInt("deptNo");
String loc = rs.getString("location");
System.out.println("Employee ID : "+id);
System.out.println("Employee Name : "+name);
System.out.println("Employee Salary : "+sal);
System.out.println("Employee Dept No : "+dept);
System.out.println("Employee Location : "+loc);
}
else
{
System.err.println("Invalid Employee ID...!!!");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Connection Established...!!!
Platform Created
Valid Employee ID.....
***************
Employee ID : 105
Employee Name : JAY
Employee Salary : 500000.0
Employee Dept No : 10
Employee Location : COCHIN
DATE : 02-09-2022
Q. WRITE A JDBC PROGRAM FOR EMPLOYEE WHO IS WORKING
IN DEPARTMENT 10
package org.jsp.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
String query = "select * from teja15.employee where deptNo=10";
try
{
Connection connection =
DriverManager.getConnection(url);
System.out.println("Connection Established...!");
Statement stmt = connection.createStatement();
System.out.println("Platform Created");
ResultSet rs = stmt.executeQuery(query);
System.out.println("Query Executed");
if(rs.last())
{
rs.beforeFirst();
while(rs.next())
{
System.out.println("***************");
System.out.println("Employee ID :
"+rs.getInt(1));
System.out.println("Employee Name :
"+rs.getString(2));
System.out.println("Employee Salary :
"+rs.getDouble(3));
System.out.println("Employee Dept No :
"+rs.getInt(4));
System.out.println("Employee Location :
"+rs.getString(5));
System.out.println("***************");
}
}
else
{
System.err.println("Invalid Employee ID...!!!");
}
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Connection Established...!
Platform Created
Query Executed
***************
Employee ID : 101
Employee Name : RAJA
Employee Salary : 100000.0
Employee Dept No : 10
Employee Location : DELHI
***************
***************
Employee ID : 103
Employee Name : RAM
Employee Salary : 50000.0
Employee Dept No : 10
Employee Location : CHENNAI
***************
***************
Employee ID : 105
Employee Name : JAY
Employee Salary : 500000.0
Employee Dept No : 10
Employee Location : COCHIN
***************
***************
Employee ID : 108
Employee Name : SAI
Employee Salary : 80000.0
Employee Dept No : 10
Employee Location : JAIPUR
***************
Q. WRITE A JDBC PROGRAM TO PRINT STUDENT ID, NAME,
STREAM IF MARKS GREATER THAN 70
package org.jsp.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
String query = "select * from teja15.student where sMarks>=70";
try
{
Connection connection =
DriverManager.getConnection(url);
System.out.println("Connection Established...");
Statement stmt = connection.createStatement();
System.out.println("Platform Created...");
ResultSet rs = stmt.executeQuery(query);
System.out.println("Query Executed...");
if(rs.last())
{
rs.beforeFirst();
while(rs.next())
{
System.out.println("***************");
System.out.println("Student ID :
"+rs.getInt(1));
System.out.println("Student Name :
"+rs.getString(2));
System.out.println("Student Stream :
"+rs.getString(3));
System.out.println("Student Marks :
"+rs.getInt(4));
System.out.println("***************");
}
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Connection Established...
Platform Created...
Query Executed...
***************
Student ID : 2
Student Name : ASHOK
Student Stream : ECE
Student Marks : 77
***************
***************
Student ID : 3
Student Name : PREM
Student Stream : EEE
Student Marks : 83
***************
***************
Student ID : 4
Student Name : SINGH
Student Stream : CE
Student Marks : 75
***************
***************
Student ID : 5
Student Name : ROSHAN
Student Stream : CSE
Student Marks : 80
***************
Q. WRITE A JDBC PROGRAM TO PRINT USER INFORMATION IF
MOBILE NUMBER ENDING WITH ‘5’.
package org.jsp.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
String query = "select * from teja15.employee";
try
{
Connection connection =
DriverManager.getConnection(url);
System.out.println("Connection Established…!");
Statement stmt = connection.createStatement();
System.out.println("Platform Created...!");
ResultSet rs = stmt.executeQuery(query);
System.out.println("Query Executed...");
while(rs.next())
{
int num = rs.getInt(1);
boolean isPrime = true;
for(int i=2;i<num;i++)
{
if(num%i==0)
{
isPrime = false;
break;
}
}
if(isPrime)
{
System.out.println("Employee Id :
"+rs.getInt(1));
System.out.println("Employee Name :
"+rs.getString(2));
System.out.println("Employee Salary :
"+rs.getDouble(3));
System.out.println("Employee DeptNo :
"+rs.getInt(4));
System.out.println("Employee Location :
"+rs.getString(5));
System.out.println("********************");
}
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Connection Established…!
Platform Created...!
Query Executed...
Employee Id : 101
Employee Name : RAJA
Employee Salary : 100000.0
Employee DeptNo : 10
Employee Location : DELHI
********************
Employee Id : 103
Employee Name : RAM
Employee Salary : 50000.0
Employee DeptNo : 10
Employee Location : CHENNAI
********************
Employee Id : 107
Employee Name : TEJA
Employee Salary : 30000.0
Employee DeptNo : 30
Employee Location : KOLKATA
********************
DATE : 05-09-2022
PREPARED STATEMENT
PreparedStatement ps = connection.prepareStatement(query);
arg
setter setInt(placeholder_position,value)
setString(placeholder_position,value)
setDouble(placeholder_position,value)
setFloat(placeholder_position,value)
package org.jdbc.prepared;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
String query = "insert into teja15.employee values(?,?,?,?,?) ";
try
{
Connection connection =
DriverManager.getConnection(url);
System.out.println("Connected...!");
PreparedStatement ps =
connection.prepareStatement(query);
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Employee ID : ");
int id = sc.nextInt();
ps.setInt(1,id);
System.out.println("Enter the Employee Name : ");
String name = sc.next();
ps.setString(2, name);
System.out.println("Enter the Employee Salary : ");
double sal = sc.nextDouble();
ps.setDouble(3,sal);
System.out.println("Enter the Employee Dept : ");
int dept = sc.nextInt();
ps.setInt(4, dept);
System.out.println("Enter the Employee Location : ");
String loc = sc.next();
ps.setString(5, loc);
ps.executeUpdate();
System.out.println("Data Inserted...!");
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Connected...!
Enter the Employee ID :
109
Enter the Employee Name :
SIMON
Enter the Employee Salary :
40000
Enter the Employee Dept :
10
Enter the Employee Location :
GURGAON
Data Inserted...!
DATE : 06-09-2022
WRITYE A JDBC PROGRAM TO DELETE A USER RECORD BY THE
MOBILE NUMBER
package org.jdbc.prepared;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
String query = "delete from teja15.user where uMobile=?";
try
{
Connection connection =
DriverManager.getConnection(url);
System.out.println("Connected...");
PreparedStatement ps =
connection.prepareStatement(query);
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Mobile Number to Delete : ");
String mobile = sc.next();
ps.setString(1, mobile);
int num = ps.executeUpdate();
if(num > 0)
{
System.out.println("Record deleted...");
}
else
{
System.err.println("Invalid Record...");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Connected...
Enter the Mobile Number to Delete :
7345234955
Record deleted...
DATE : 07-09-2022
WRITE A JDBC PROGRAM TO UPDATE SALARY WHO BORN
AFTER 2005 TO UPDATE VALIDATE THEIR MOBILE NUMBER
WITH OTP
package org.jdbc.prepared;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Random;
import java.util.Scanner;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
String query = "select * from teja15.employee where empDOB>?";
try
{
Connection connection =
DriverManager.getConnection(url);
System.out.println("Connected");
PreparedStatement ps =
connection.prepareStatement(query);
Scanner sc = new Scanner(System.in);
System.out.println("Enter the DOB : ");
String dob = sc.next();
ps.setString(1,dob);
ResultSet rs = ps.executeQuery();
if(rs.last())
{
rs.beforeFirst();
while(rs.next())
{
System.out.println("Emp Id : "+rs.getInt(1));
System.out.println("Emp Name :
"+rs.getString(2));
System.out.println("Emp Sal :
"+rs.getDouble(3));
System.out.println("Emp Dept : "+rs.getInt(4));
System.out.println("Emp Location :
"+rs.getString(5));
System.out.println("Emp DOB :
"+rs.getString(6));
System.out.println("Emp Mobile :
"+rs.getString(7));
System.out.println("***************");
System.out.println("Enter the Mobile Number :
");
String mobile = sc.next();
if(mobile.equals(rs.getString(7)))
{
Random r = new Random();
int otp = r.nextInt(10000);
if(otp<1000)
{
otp+=1000;
}
System.out.println("OTP : "+otp);
System.out.println("Enter the OTP for
verification : ");
int user = sc.nextInt();
if(user == otp)
{
query = "update teja15.employee
set empSal=empSal+empSal*0.1 where empMOB='"+mobile+"'and
empDOB>'"+dob+"'";
PreparedStatement ps1 =
connection.prepareStatement(query);
ps1.executeUpdate();
System.out.println("Salary
Updated...!");
}
else
{
System.err.println("Invalid
OTP...!!!");
}
}
else
{
System.err.println("Invalid Mobile
Number...!!!");
}
}
}
else
{
System.err.println("No Data Found");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Connected
Enter the DOB :
2004-12-31
Emp Id : 102
Emp Name : ASHOK
Emp Sal : 200000.0
Emp Dept : 20
Emp Location : BANGLORE
Emp DOB : 2006-05-31
Emp Mobile : 9876543210
***************
Enter the Mobile Number :
9876543210
OTP : 9688
Enter the OTP for verification :
9688
Salary Updated...!
Emp Id : 105
Emp Name : JAY
Emp Sal : 500000.0
Emp Dept : 10
Emp Location : COCHIN
Emp DOB : 2007-02-08
Emp Mobile : 8798634564
***************
Enter the Mobile Number :
8798634564
OTP : 4824
Enter the OTP for verification :
4824
Salary Updated...!
Emp Id : 107
Emp Name : TEJA
Emp Sal : 30000.0
Emp Dept : 30
Emp Location : KOLKATA
Emp DOB : 2007-12-28
Emp Mobile : 6543277379
***************
Enter the Mobile Number :
6543277379
OTP : 1026
Enter the OTP for verification :
1026
Salary Updated...!
1. By Mobile number
2. By Name
DATE : 08-09-2022
STORED PROCEDURES
==> The methods which is present in database to store the queries permanently
is known as Stored procedures.
==> If the query is present in the Java application it will affects to application
performance.
==> If the query is present in the Database in order to compile and execute we
will take short process and less time, So it will not affect to application
performance.
------------------------------------------------------------------------------------------------
NOTE :
------------------------------------------------------------------------------------------------
SYNTAX:
BEGIN
END $$
Syntax of prepareCall( )
prepareCall(“call database_name.Stored_procedure_name”);
CallableStatement cs = connection.prepareCall(“call
database_name.Stored_procedure_name”);
where
package org.jsp.callable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
try
{
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost:3306?user=root&passwo
rd=12345");
System.out.println("Connection Established");
CallableStatement cs = connection.prepareCall("call
teja15.EmpInsert");
cs.executeUpdate();
System.out.println("Stored procedure called successfully");
connection.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
OUTPUT
Connection Established
Stored procedure called successfully
BEGIN
END$$
package org.jsp.callable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
try
{
Connection connection =
DriverManager.getConnection(url);
System.out.println("Connection Established");
CallableStatement cs = connection.prepareCall("call
teja15.EmpDelete");
cs.executeUpdate();
System.out.println("Stored procedure called successfully");
System.out.println("Record Deleted Successfully");
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Connection Established
Stored procedure called successfully
Record Deleted Successfully
DATE : 10-09-2022
STORED PROCEDURE WITH ARGUMENT
BEGIN
END$$
package org.jsp.callable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Scanner;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
try
{
Connection connect = DriverManager.getConnection(url);
System.out.println("Cnnection Established");
CallableStatement cs = connect.prepareCall("call
teja15.empDeletion(?)");
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Employee ID to delete the
Record : ");
cs.setInt(1, sc.nextInt());
cs.executeUpdate();
System.out.println("Record deleted...!!!");
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
Cnnection Established
Enter the Employee ID to delete the Record :
108
Record deleted...!!!
DATE : 12-09-2022
CREATE A STORED PROCEDURE TO UPDATE EMAIL IF MOBILE
NUMBER AND PASSWORD PRESENT IN DATABASE AND
PERFORM THE VERIFICATION BY DATE OF BIRTH
package org.jsp.callable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
try
{
Connection connect = DriverManager.getConnection(url);
String query = "select * from teja15.user where uMobile=?
and uPwd =?";
PreparedStatement ps = connect.prepareStatement(query);
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Mobile Number : ");
ps.setString(1,sc.next());
System.out.println("Enter the Password : ");
ps.setString(2,sc.next());
ResultSet rs = ps.executeQuery();
if(rs.next())
{
System.out.println("Enter DOB for 2nd Verification :
");
String dob = sc.next();
if(dob.equals(rs.getString(6)))
{
System.out.println("Valid DOB...!");
CallableStatement cs =
connect.prepareCall("call teja15.updMail(?,?)");
System.out.println("Enter the New Email : ");
cs.setString(1, sc.next());
cs.setString(2, rs.getString(3));
cs.executeUpdate();
System.out.println("Mail Updated");
}
else
{
System.err.println("Invalid DOB...!!!");
}
}
else
{
System.err.println("Invalid Mobile OR
Password...!!!");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
package org.jsp.callable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Scanner;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
try
{
Connection connect = DriverManager.getConnection(url);
CallableStatement cs = connect.prepareCall("call
teja15.updSTD(?,?,?,?)");
Scanner sc = new Scanner(System.in);
System.out.println("Enter the New Stream : ");
cs.setString(1,sc.next());
System.out.println("Enter the New Marks : ");
cs.setDouble(2,sc.nextDouble());
System.out.println("Enter Student Name : ");
cs.setString(3,sc.next());
System.out.println("Enter the Student ID : ");
int temp = sc.nextInt();
if(temp%2==0)
{
cs.setInt(4,temp);
int num = cs.executeUpdate();
if(num>0)
{
System.out.println("Record Updated...!");
}
else
{
System.err.println("INVALID STUDENT
NAME OR ID...!!!");
}
}
else
{
System.err.println("STUDENT ID IS ODD...!!!");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
package org.jsp.callable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
String url =
"jdbc:mysql://localhost:3306?user=root&password=12345";
String query = "select * from teja15.student";
try
{
Connection connect = DriverManager.getConnection(url);
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery(query);
int gcount = 0;
int lcount = 0;
if(rs.last())
{
rs.beforeFirst();
while(rs.next())
{
if(rs.getDouble(4)>60)
{
gcount++;
}
else
{
lcount++;
}
}
System.out.println(gcount+" Students have greater
than 60 marks");
System.out.println(lcount+" Students have less than
60 marks");
}
else
{
System.err.println("NO RECORDS PRESENT IN
TABLE");
}
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
OUTPUT
SERVLETS
==> Servlet is not a server, it is a Class.
Web Application
Frontend Backend
JAVASCRIPT SQL
1. Multi-Threaded
2. Session
1. MULTI THREADED
==> If an application which can be used by multiple users at the same time is
known as Multithreaded.
SINGLE THREADED
==> If an application can access by only user where other user have to wait to
access an application is known as Single Threaded.
2. SESSION
==> Session is nothing but time interval which is given to the application by the
Developer.
==> The applications which are developed by using Session feature the
operation should be complete within given particular time.
==> If we tried to access an application after the time interval we will get
“Session Time Out”.
DEPLOYMENT
1. Manual Deployment
2. Automated Deployment
1. MANUAL DEPLOYMENT
==> In Manual Deployment programmers are responsible for writing the code
and giving the application to the server.
2. AUTOMATED DEPLOYMENT
------------------------------------------------------------------------------------------------
NOTE:
------------------------------------------------------------------------------------------------
JEE CONTAINER
1. Segregation of files