Professional Documents
Culture Documents
QA AJP 22517 Exp 19
QA AJP 22517 Exp 19
Ans:-
• PreparedStatement prevents SQL injection threats as it automatically escapes the special
characters.
• Precompiles and caches the SQL statement for faster execution and to reuse the same
SQL statement in batch.
• PreparedStatement provides clear separation between the query code and the parameter
values that improves readability.
• PreparedStatement provides convenient way to transform Java object types to SQL Data
types to pass input parameters.
2. Explain the methods of ResultSet Interface ?
Ans:-
Methods Description
public boolean absolute(int row) Moves the cursor to the specified row in the ResultSet object.
It moves the cursor just before the first row i.e. front of the
public void beforeFirst( )
ResultSet.
Moves the cursor to the end of the ResultSet object, just after
public void afterLast()
the last row.
public boolean first() Moves the cursor to first value of ResultSet object.
public boolean last( ) Moves the cursor to the last row of the ResultSet object.
Just moves the cursor to the previous row in the ResultSet
public boolean previous ( )
object.
public boolean next( ) It moves the curser forward one row from its current position.
It retrieves the value of the column in current row as int in
public intgetInt(intcolIndex)
given ResultSet object.
public String getString( It retrieves the value of the column in current row as int in
intcolIndex) given ResultSet object.
public void relative(int rows) It moves the cursor to a relative number of rows.
1] TYPE_FORWARD_ONLY:
The result set cannot be scrolled; its cursor moves forward only, from before the first row to
after the last row. The rows contained in the result set depend on how the underlying database
generates the results. That is, it contains the rows that satisfy the query at either the time the
query is executed or as the rows are retrieved.
TYPE_SCROLL_INSENSITIVE:
The result can be scrolled; its cursor can move both forward and backward relative to the
current position, and it can move to an absolute position. The result set is insensitive to
changes made to the underlying data source while it is open. It contains the rows that satisfy
the query at either the time the query is executed or as the rows are retrieved.
TYPE_SCROLL_SENSITIVE:
The result can be scrolled; its cursor can move both forward and backward relative to the
current position, and it can move to an absolute position. The result set reflects changes made
to the underlying data source while the result set remains open.
E.g:
Statement st = con.createStatement();
st.executeUpdate("insert employees...");
st.executeUpdate("update employees...");
st.executeUpdate("delete employees...");
5. State the use and syntax of following method of resultset interface that involve moving
the cursor.
1] beforefirst() 2] afterlast() 3] first() 4] last()
Answer:-
1] This ResultSet method set cursor to before first record. It sets the cursor position to 0. It
indicates whether the cursor is before the first row in this ResultSet object.
Syntax: ResultSet rs; void rs.beforeFirst();
3) public boolean first(): is used to move the cursor to the first row in result set object.
Syntax: ResultSet rs; void rs.first();
4) public boolean last(): is used to move the cursor to the last row in result set object.
Syntax: ResultSet rs; void rs.last();