Class Running Notes 10th To 18th August
Class Running Notes 10th To 18th August
Define Application?
define WebApplications?
as WebApplication.
1.JDBC
2.Servlet
3.JSP
Diagram:
-----------------------------------------------------------------------------
*imp
1.JDBC:(Part-1)
=>JDBC stands for 'Java DataBase Connectivity' and which is used to establish
(a)Field Storage
(b)Object Storage
(c)File Storage
(d)DataBase Storage
(a)Field Storage:
=>The memory which is created part of JavaApplication to hold Single data value is known
as Field Storage.
=>These Field Storages will be created when we use Primitive DataTypes like byte,short,
Exp:
int k = 10;
(b)Object Storage:
=>The memory which is created part of JavaApplication to hold group members is known as
Object Storage.
=>These Object Storages will be created when we use NonPrimitive DataTypes like class,
interface,Array and Enum.
Exp:
class Addition
int a,b;
void add()
System.out.println("Sum:"+(a+b));
Diagram:
Note:
=>The Field Storages and the Object Storages which are created part of JVM while
=>Java Applications need Permanent Storages,because of this reason we use the following:
=>File Storage
=>DataBase Storage
---------------------------------------------------------------------------------------
Dt : 11/8/2021
(c)File Storage:
=>The smallest permanent storage of Computer System which is controlled and managed
Note:
=>In the process of establishing communication b/w JavaApp and File Storage,the JavaApp
must be constructed using the classes and interfaces available from 'java.io' package.
Diagram:
----------------------------------------------------------------------------
1.Data Redundancy
2.Data Inconsistency
5.Integrity Problems
6.Atomicity problems
8.Security Problems.
1.Data Redundancy:
2.Data Inconsistency:
5.Integrity Problems:
6.Atomicity problems:
=>Atomicity means complete the transaction entirely or not at all,which is not posible
if File Storage.
8.Security Problems:
Note:
WebApplications.
-------------------------------------------------------------------------------------
Dt : 12/8/2021
faq:
define API?
=>API stands for 'Application Programming Interface' and which is collection of 'classes
-------------------------------------------------------------------------------------
*imp
(d)DataBase Storage:
Note:
=>In the process of establishing communication b/w JavaApp and DB Storage,the JavaApp must
be constructed using 'classes and Interfaces' available from 'java.sql' package and the
Diagram:
----------------------------------------------------------------------------------------
faq:
define 'driver'?
Exp:
Audio driver
Video driver
N/w driver
...
---------------------------------------------------------------------------------------
faq:
=>JDBC driver is used to establish connection b/w JavaApp and DataBase Storage.
4.Thin Driver(Type-4)
Note:
=>In realtime we use 'Thin driver(Type-4)' to establish communication b/w JavaApp and
DataBase Storage.
------------------------------------------------------------------------------------
Dt : 13/8/2021
*imp
Installing DataBase Product(Oracle) and making the system Environment ready for executing
JDBC Applications:
sql>connect
(press enter)
-------------------------------------------------------------------
step-5 : Dowload DB Jar file related to DB Product
oracle10 - ojdbc14.jar
oracle11 - ojdbc6.jar
oracle12 - ojdbc7.jar,ojdbc8.jar
Note:
C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6.jar
MySql - mysql-connector-java-VERSION.jar
-------------------------------------------------------------------------------
C:\Program Files\Java\jdk1.8.0_31\jre\lib\ext
Note:
=>If 'ext' folder is not available then create one user defined folder with any name in
-------------------------------------------------------------------------------------
=>To know PortNo and ServiceName,open 'tnsnames.ora' file from 'ADMIN' as follows:
C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN
Port No : 1521
Service Name : XE
=====================================================================================
Dt : 14/8/2021
*imp
we use the following steps to establish communication b/w JavaProgram and DB Product:
=====================================================================================
===
*imp
1.Open IDE Eclipse,while opening name the WorkSpace and click ok or Launch.
and click Add External Jars->Browse and select DB Jar file from 'ext' folder or select from
6.Write the following code to display the records from the DB Table 'Employee35'
package test;
import java.sql.*;
try {
Class.forName("oracle.jdbc.driver.OracleDriver"); //step-1
("jdbc:oracle:thin:@localhost:1521:XE","system","manager");//step-2
while(rs.next())
System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t"+
rs.getString(3)+"\t"+rs.getInt(4));
}//end of loop
con.close();//step-5
}catch(Exception e) {e.printStackTrace();}
o/p:
=====================================================================================
===
DT : 16/8/2021
=>The process of loading JDBC driver to current running program is known as Loading Driver.
Method Signature:
throws java.lang.ClassNotFoundException;
syntax:
Class c = Class.forName("DriverClass");
(or)
Class.forName("DriverClass");
Note:
---------------------------------------------------------------------------
as Creating Connection.
Method Signature:
public static java.sql.Connection getConnection(java.lang.String,java.lang.String,
java.lang.String)throws java.sql.SQLException;
syntax:
Uname==> system
Pword==> manager
faq:
define 'Connection'?
'Connection' is an interface from java.sql packge and which provides the following
=>createStatement()
=>prepareStatement()
=>prepareCall()
=>close()
Execution behaviour of getConnection() method:
=>This object reference is copied on to reference variable(con) and the object will hold
-----------------------------------------------------------------------------
(i)Statement
(ii)PreparedStatement
(iii)CallableStatement
(i)Statement:
normal queries.
Method Signature:
syntax:
(a)executeQuery()
(b)executeUpdate()
(a)executeQuery():
Method Signature:
throws java.sql.SQLException;
syntax:
ResultSet rs = stm.executeQuery("query");
(b)executeUpdate():
Method Signature:
syntax:
int k = stm.executeUpdate("query");
--------------------------------------------------------------------------------
Dt : 17/8/2021
=>we use close() method from 'Connection' interface to perform closing operation.
Method Signature:
faq:
define ResultSet?
=>'ResultSet' is an interface from java.sql package and which is used to hold the result
=>we use executeQuery() method to create the implementation object of 'ResultSet' interface
=>we use 'next()' method from 'ResultSet' to move the corsor row-by-row,when the row(record)
=>we use the following 'getter methods' from 'ResultSet' to retrieve the data based on
column_no or column_name.
===============================================================================
Assignment1:
(bcode,bname,bauthor,bprice,bqty)
=================================================================================
Exp program:
(pcode,pname,pprice,pqty)
step2 : Construct JDBC application to read product details from Console(Keyboard) and insert
DBCon2.java
package test;
import java.sql.*;
import java.util.*;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
int k = stm.executeUpdate
if(k>0) {
con.close();
s.close();
}catch(Exception e) {e.printStackTrace();}
o/p:
A111
Enter the ProdName:
Mouse
1200
12
--------------------------------------------------------------------------------------
Note:
=>In the above program 'k' will hold the value equal to the number of records updated in
DB Table.
------------------------------------------------------------------------------------
Assignment2:
Assignment3:
-------------------------------------------------------------------------------------
Dt : 18/8/2021
JDBC Statements:
(i)Statement
(ii)PreparedStatement
(iii)CallableStatement
(i)Statement:
syntax:
Exp:
above programs
(ii)PreparedStatement:
Method Signature:
throws java.sql.SQLException;
syntax:
PreparedStatement ps = con.prepareStatement("query-structure");
(a)executeQuery()
(b)executeUpdate()
(a)executeQuery():
syntax:
ResultSet rs = ps.executeQuery();
(b)executeUpdate():
Method Signature:
syntax:
int k = ps.executeUpdate();
--------------------------------------------------------------------------
Example program:
(bcode,bname,bauthor,bprice,bqty)
step2 :Construct JDBC Application to read data from Console and insert into DB Table 'Book35'
DBCon3.java
package test;
import java.sql.*;
import java.util.*;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
PreparedStatement ps = con.prepareStatement
ps.setString(1,bCode);
ps.setString(2,bName);
ps.setString(3, bAuthor);
ps.setFloat(4,bPrice);
ps.setInt(5, bQty);
int k = ps.executeUpdate();
if(k>0) {
con.close();
s.close();
}catch(Exception e) {e.printStackTrace();}
o/p:
A121
C-Lang
B-Swamy
567.89
10
--------------------------------------------------------------------------------
Example program:
Construct JDBC Application to insert multiple BookDetails based on User Choice?
DBCon4.java
package test;
import java.sql.*;
import java.util.*;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
PreparedStatement ps = con.prepareStatement
int n = Integer.parseInt(s.nextLine());
for(int i=1;i<=n;i++) {
ps.setString(1,bCode);
ps.setString(2,bName);
ps.setString(3, bAuthor);
ps.setFloat(4,bPrice);
ps.setInt(5, bQty);
int k = ps.executeUpdate();
if(k>0) {
}//end of loop
con.close();
s.close();
}catch(Exception e) {e.printStackTrace();}
o/p:
CJ
XYZ
1200
12
A123
AJ
PQR
1300
23
A124
HB
Enter the BAuthor3
ABC
2345.67
21
--------------------------------------------------------------------------------------
Exp program:
DCon5.java
package test;
import java.sql.*;
import java.util.*;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
PreparedStatement ps = con.prepareStatement
("select * from Book35 where bcode=?");
ps.setString(1,bCode);
ResultSet rs = ps.executeQuery();
if(rs.next()) {
System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t"+
rs.getString(3)+"\t"+rs.getFloat(4)+"\t"+rs.getInt(5));
}else {
System.out.println("Invalid bookCode...");
con.close();
s.close();
}catch(Exception e) {e.printStackTrace();}
o/p:
A123
------------------------------------------------------------------------