Tuesday, 24 September 2019
Monday, 9 September 2019
Difference between Statement, prepared Statement and Callable Statement
Statement:
Statement is used to execute normal SQLs , it won't take any parameters. Generally preferable for DDL statements and normal SQLs without any parameters.
Statement st=conn.createStatement();
st.execute("create table tableA (columnA int not null, columnB varchar(255) )");
Prepared Statement:
Prepared statement is used to execute dynamic SQLs with parameters, it extends Statement interface.If you are executing the same query multiple times, its preferable to use to the prepared statement , since it pre-compiles the statements
PreparedStatement prepStmt= conn.prepareStatement("update tableA set column1=? where column2=?");
prepStmt.setString(1, "test"); prepStmt.setInt(2, 444);Callable Statement: Execute a call to a database stored procedure. it extends statement interface . It allows the user to send parameters to procedure and retrieve the data from procedure.
CallableStatement cStmt= conn.prepareCall("call procA(?,?,?)")
cStmt.setString(1,"test");
cStmt.setInt(2,444);
cStmt.registerOutParameter(3);
cStmt.execute();
Tuesday, 3 September 2019
OOPS concepts and exmples
Object Oriented programs and concepts
What is Object oriented program
Object oriented program is the concept of the principle that works objects are most important of a program that users are building. An object is set of variables, methods and objects. Manipulating the objects to get the result is the aim of object oriented program.
OOPS Concepts
Class
Object
Inheritance
Abstraction
Encapsulation
Polymorphism
Association
Aggregation
Composition
Class :
A class is user defined blueprint or prototype for which the objects are created. It can simply say combination of variables , methods and other objects .
Object:
Object is self contained component which consists of method and variables which makes particular type of data is useful to user. In simple terms Object is the instantiation of a class , which is ready to use for a purpose .
Inheritance:
Inheritance, is the concept of acquiring/getting/using the properties of another object in one object, basically creating parent child relationship between classes.
the keyword extends used to inherit the properties . Class A extends B means , all the properties of B can be used in Class A.
Abstraction:
Inheritance Abstraction is the process by which the data and programs are defined with representation while hiding the implementation details.
In simple terms , Abstraction is to hide the information which is not relevant to others/other objects.
Encapsulation:
Wrapping data and methods within classes in combination with implementation hiding (through access specifiers/modifiers) is called encapsulation. Encapsulation essentially has both information hiding and implementation hiding.
Polymorphism:
Polymorphism is the ability by which, the functions or reference variables which behaves differently in different programmatic context.
two types of polymophisms available:
Compile time polymorphism (static binding or method overloading)
Run-time polymorphism (dynamic binding or method overriding)
Association:
Association is the concept of building relationship between two classes , but the association defined as is a relation or has a relation between classes .
Aggregation:
Aggregation is the concept of having relationship only in one direction .
Composition :
Composition is the type of both directional relationship. Object A to B and B to A , if the Object A is not defied Object B will not exist and Object B is not defined Object A will not exist.
Subscribe to:
Comments (Atom)