Found 317 Articles for JDBC

What is TYPE_SCROLL_SENSITIVE ResultSet in JDBC?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

3K+ Views

This represents is a scrollable ResultSet i.e. the cursor moves in forward or backward directions. This type of ResultSet is sensitive to the changes that are made in the database i.e. the modifications done in the database are reflected in the ResultSet.Which means if we have established a connection with a database using a JDBC program and retrieved a ResultSet holding all the records in a table named SampleTable. Meanwhile, if we have added some more records to the table (after retrieving the ResultSet), these recent changes will be reflected in the ResultSet object we previously obtained.Following is an example ... Read More

What is TYPE_SCROLL_INSENSITIVE ResultSet in JDBC?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

2K+ Views

This represents a scrollable ResultSet i.e. the cursor moves in forward or backward directions. This type of ResultSet is insensitive to the changes that are made in the database i.e. the modifications done in the database are not reflected in the ResultSet.Which means if we have established a connection with a database using JDBC program and retrieved a ResultSet holding all the records in a table named SampleTable and, meanwhile if we add some more records to the table (after retrieving getting the ResultSet), these recent changes will not be reflected in the ResultSet object we previously obtained.ExampleConsider we have ... Read More

What is Type_FORWARD_ONLY ResultSet in JDBC?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

2K+ Views

A ResultSet interface in JDBC represents the tabular data generated by SQL queries. It has a cursor which points to the current row. Initially, this cursor is positioned before the first row.You can retrieve the column value at the current row using the getter methods getInt(), getString(), getDate() etc…To move the cursor and to navigate/iterate through the ResultSet the java.sql.ResultSet interface provides various methods such as next(), Previous(), first(), last(), relative(), absolute(), beforeFirst(), afterLast() etc...Type_FORWARD_ONLY Only ResultSetIn forward only ResultSet you can move the cursor only in forward direction. By default, a ResultSet is of type forward only.Read More

How to handle Exceptions while working with JDBC applications?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

129 Views

Whenever a JDBC application encounters an issue while executing SQL statements an SQLException is thrown.This class provides information on the errors that occur while interacting with the database.Following are the main methods of the SQLException class:Sr.NoMethod & Description1int getErrorCode()This method returns the exception code for the Exception occurred.2SQLException setNextException(SQLException ex)Using this method you can create a chain of exceptions by adding a new exception to the current exception.3String getSQLState()This method returns the SQLState of the current exception.4Iterator iterator()This method returns an iterator to iterate through the chain of SQLExceptions.5void getNextException(SQLException ex)This method is used to retrieve next SQLException in this ... Read More

What is RowId object in JDBC Explain?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

401 Views

A RowId is a built-in type of SQL which is an address of a row in a table of a database. The RowId interface of the java.sql package maps with the SQL ROWID value.RowId values are unique for every row and they are the fastest way to access a row. You cannot use this as a primary key of a table.Retrieving RowId objectsYou can retrieve the RowId of a particular row using the getRowId() method of the ResultSet, CallableStatement, PreparedStatement interfaces.This method accepts a String value representing a column label or, an integer value representing the column index and returns ... Read More

How to process SQL statements with JDBC explain with an example?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

4K+ Views

To process an SQL statement, you need to follow the steps given below:Establish the connection.Create a statement.Execute the statement/query.Process the result.Close the connection.Establishing a ConnectionTo process SQL statements first of all you need to establish connection with the desired DBMS or, file System or, other data sources.To do so, Register the JDBC driver class, corresponding to the DataSource you need to the DriverManager using the registerDriver() method.Driver myDriver = new com.mysql.jdbc.Driver(); DriverManager.registerDriver(myDriver);This method accepts an object of the Driver class; it registers the specified Driver with the DriverManager.You can also register the driver using the forName() method. This method loads ... Read More

How do I find out whether the underlying database supports batch processing?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

187 Views

Not all the databases support batch processing therefore before proceeding with batch updates in your application. You need to verify whether the database you are trying to communicate supports batch processing/batch updates or not.You can do so using the supportsBatchUpdates() method of the DatabaseMetaData interface.Follow the steps given below:Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as a parameter.Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create a DatabaseMetaData object using the getMetaData() method of ... Read More

Write an example JDBC program demonstrating the batch processing with CallableStatement object?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

596 Views

Grouping related SQL statements into a batch and executing/submitting them at once is known as batch processing. The Statement interface provides methods to perform batch processing such as addBatch(), executeBatch(), clearBatch().Follow the steps given below to perform batch updates using the CallableStatement object:Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as a parameter.Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Set the auto-commit to false using setAutoCommit() method of the Connection interface.Create a CallableStatement object ... Read More

Write an example JDBC program demonstrating the batch processing with PreparedStatement object?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

108 Views

Grouping related SQL statements into a batch and executing/submitting them at once is known as batch processing. The Statement interface provides methods to perform batch processing such as addBatch(), executeBatch(), clearBatch().Follow the steps given below to perform batch updates using the PreparedStatement object:Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as a parameter.Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Set the auto-commit to false using setAutoCommit() method of the Connection interface.Create a PreparedStatement object ... Read More

Write an example JDBC program demonstrating the batch processing with statement object?

Nancy Den
Updated on 30-Jul-2019 22:30:25

110 Views

Grouping related SQL statements into a batch and executing/submitting them at once is known as batch processing. The Statement interface provides methods to perform batch processing such as addBatch(), executeBatch(), clearBatch().Follow the steps given below to perform batch updates using the Statement object:Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as a parameter.Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create a Statement object using the createStatement() method of the Connection interface.Set the auto-commit to ... Read More

Advertisements