Statement:
When you use normal statements compilation of statement or
parsing of statement will happen every time. This is time
consuming when u have multiple queries to execute.
Statement s = conn.createStatement();
s.executeQuery();
Prepared Statement:
In prepared statement SQL query will be compiled or parsed
for the very first time and kept in some kind of pool. When
u execute one more time the same statement with different
values it saves the parsing time.
The PreparedStatement is a slightly more powerful version of a Statement, and should always be at least as quick and easy to handle as a Statement.
The PreparedStatement may be parametrized.
Prepared statement is precompiled statement it is used when
we want one query to be executed n no. of times.
Prepared Statement is Pre-compiled class , but Statement is not.
So in PreparedStatement the execution will be faster.
SQL select * from employee where employeeID=?,empName=?;
PreparedStatement ps = conn.PreparedStatement();
ps.execute(1,aru);
ps.execute(2,arya);
Callable Statement:
Callable statements are used to execute stored procedures
similar to java functions.
Search This Blog
Sunday, 18 December 2011
Tuesday, 6 December 2011
Object Class functions in java
Object Class
Object Class is the Super class for all classes in JAVA.The Object class defines the basic state and behavior that all objects must have, such as the ability to compare oneself to another object, to convert to a string, to wait on a condition variable, to notify other objects that a condition variable has changed, and to return the object's class.
The Object Class Functions:
equals:
This function is used to compare two objects whether they have equivalent values are not.
It returns true if they are equal else returns false.
The getClass() Method:
The getClass method is a final method (cannot be overridden)
This method returns a Class object.With this class you can get the information of object like name, its super class, and the names of the interfaces that it implements.
use of the getClass method is to create a new instance of a class without knowing what the class is at compile time. This sample method creates a new instance of the same class as obj which can be any class that inherits from Object (which means that it could be any class):
Object createNewInstanceOf(Object obj) {
return obj.getClass().newInstance();
}
The toString Method
Object's toString method returns a String representation of the object. You can use toString to display an object.
The Object class also provides five methods that are critical when writing multithreaded Java programs:
• notify
• notifyAll
• wait (three versions)
hashCode()
Returns a hash code value for the object.
finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
Object Class is the Super class for all classes in JAVA.The Object class defines the basic state and behavior that all objects must have, such as the ability to compare oneself to another object, to convert to a string, to wait on a condition variable, to notify other objects that a condition variable has changed, and to return the object's class.
The Object Class Functions:
equals:
This function is used to compare two objects whether they have equivalent values are not.
It returns true if they are equal else returns false.
The getClass() Method:
The getClass method is a final method (cannot be overridden)
This method returns a Class object.With this class you can get the information of object like name, its super class, and the names of the interfaces that it implements.
use of the getClass method is to create a new instance of a class without knowing what the class is at compile time. This sample method creates a new instance of the same class as obj which can be any class that inherits from Object (which means that it could be any class):
Object createNewInstanceOf(Object obj) {
return obj.getClass().newInstance();
}
The toString Method
Object's toString method returns a String representation of the object. You can use toString to display an object.
The Object class also provides five methods that are critical when writing multithreaded Java programs:
• notify
• notifyAll
• wait (three versions)
hashCode()
Returns a hash code value for the object.
finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
Thursday, 1 December 2011
System.out.println
Some people dont know what is System,out,println in System.out.println.
As per my Knowledge,
System is a class in java which is final class(Final will stop inheritance)
out is a static final PrintStream object that is in System Class
And println is a function in PrintStream class
Since out is a static object with out creating object we can access
directly
As
System.out.println();
As per my Knowledge,
System is a class in java which is final class(Final will stop inheritance)
out is a static final PrintStream object that is in System Class
And println is a function in PrintStream class
Since out is a static object with out creating object we can access
directly
As
System.out.println();
Subscribe to:
Posts (Atom)