The object of ResultSet maintains a cursor pointing to a particular row of data. Initially, cursor points to before the first row.
By default, ResultSet object can be moved forward only and it is not updatable.
But we can make this object to move forward and backward direction by passing either TYPE_SCROLL_INSENSITIVE or TYPE_SCROLL_SENSITIVE in createStatement(int,int) method as well as we can make this object as updatable by:
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
Commonly used methods of ResultSet interface:
- public boolean next(): is used to move the cursor to the one row next from the current position.
- public boolean previous(): is used to move the cursor to the one row previous from the current position.
- public boolean first(): is used to move the cursor to the first row in result set object.
- public boolean last(): is used to move the cursor to the last row in result set object.
- public boolean absolute(int row): is used to move the cursor to the specified row number in the ResultSet object.
- public boolean relative(int row): is used to move the cursor to the relative row number in the ResultSet object, it may be positive or negative.
- public int getInt(int columnIndex): is used to return the data of specified column index of the current row as int.
- public int getInt(String columnName): is used to return the data of specified column name of the current row as int.
- public String getString(int columnIndex): is used to return the data of specified column index of the current row as String.
- public String getString(String columnName): is used to return the data of specified column name of the current row as String.
For example of ResultSet follow below links:
Learn More on JDBC
Follow below links to learn more on JDBC and solving JDBC related issues :
Like this:
Like Loading...
- A Connection is the session between java application and database. The Connection interface is a factory of Statement, PreparedStatement, and DatabaseMetaData i.e. object of Connection can be used to get the object of Statement and DatabaseMetaData. By default, connection commits the changes after executing queries.
The Connection interface provide many methods for transaction management like commit(),rollback() etc.
Commonly used methods of Connection interface are:
- public Statement createStatement(): creates a statement object that can be used to execute SQL queries.
- public Statement createStatement(int resultSetType, int resultSetConcurrency): Creates a Statement object that will generate ResultSet objects with the given type and concurrency.
- public void setAutoCommit(boolean status): is used to set the commit status. By default it is true.
- public void commit(): saves the changes made since the previous commit/rollback permanent.
- public void rollback(): Drops all changes made since the previous commit/rollback.
- public void close(): closes the connection and Releases a JDBC resources immediately.
For example of connections follow below links:
More on JDBC
Follow below links to learn more on JDBC and solving JDBC related issues :
Like this:
Like Loading...
JDBC API introduced statement, PreparedStatement and CallableStatemnet to execute different types of queries:
- Statement : Used to execute Normal SQL Queries.
- PreparedStatement: Used to execute dynamic or parameterized queries.
- CallableStatement: Used to execute StoredProcedure.
Statement Vs PreparedStatement Vs CallableStatement
Statement |
Prepared Statement |
Callable Statement |
It is used to execute normal SQL queries. |
It is used to execute dynamic or parameterized SQL queries. |
It is used to execute Stored procedure or function. |
It is proffered when particular query to be executed only once. |
It is proffered when particular query to be executed multiple times. |
It is proffered when stored procedure or functions to be executed. |
You can no pass parameter to query by using this interface. |
You can pass parameter to query at run time by using this interface. |
You can pass three types of parameters by using this interface IN, OUT and IN OUT |
This interface mainly used for DDL statements like CREATE, ALTER , DROP etc. |
This is used to be any kind of SQL queries which are used multiple times |
It is used with Stored Procedure and functions. |
The performance of this interface is very low. |
The performance of this interface is better than query while using with multiple queries. |
Performance of this interface is very high because stored procedure execute on database end. |
For More: Statement |
For More: Prepared Statement |
For More: Callable Interface |
Learn More on JDBC
Follow below links to know more on JDBC and solving JDBC issues :
Like this:
Like Loading...
“Learn From Others Experience"