Found 317 Articles for JDBC

What are the important methods of the SQLException class?

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

166 Views

An SQLException can occur both in the driver and the database. When such an exception occurs, an object of type SQLException will be passed to the catch clause.The passed SQLException object has the following methods available for retrieving additional information about the exception:MethodDescriptiongetErrorCode( )Gets the error number associated with the exception.getMessage( )Gets the JDBC driver's error message for an error, handled by the driver or gets the Oracle error number and message for a database error.getSQLState( )Gets the XOPEN SQLstate string. For a JDBC driver error, no useful information is returned from this method. For a database error, the five-digit ... Read More

How many types of Result Sets are there in JDBC What are they?

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

4K+ Views

There are two types of result sets namely, forward only and, bidirectional.Forward only ResultSet: The ResultSet object whose cursor moves only in one direction is known as forward only ResultSet. By default, JDBC result sets are forward-only result sets.You can move the cursor of the forward only ResultSets using the next() method of the ResultSet interface. It moves the pointer to the next row from the current position. This method returns a boolean value. If there are no rows next to its current position it returns false, else it returns true.Therefore, using this method in the while loop you can ... Read More

What is the use of the method setAutoCommit() in JDBC?

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

2K+ Views

If you commit a database, it saves all the changes that have been done till that particular point.You can commit a database using the commit() method. Whenever any issue occurs you can revert the database to this point using the rollback() method. By default, some databases commit the databases automatically. But, while managing transactions you need to commit the database manually.In this scenario you can use the setAutoCommit() method. This method belongs to the Connection interface and, it accepts a boolean value.If you pass true to this method it turns on the auto-commit feature of the database and, if you ... Read More

How many locking systems are there in JDBC?

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

532 Views

You can lock a record, set of records, database table, table-space etc. and when we do we cannot change the locked values. Following are the types of locking in JDBC:Row and Key Locks: These are used to lock a particular row. Using these locks, you can achieve concurrency.Page Locks: These are used to lock a page. If you apply this, whenever the contents of a row changes, the database locks the entire page which holds the row. If you need to update/change large number of rows at once you can use this lock.Table Locks: You can lock a table using ... Read More

What is ResultSetMetaData in JDBC? What is its significance?

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

4K+ Views

The ResultSetMetaData provides information about the obtained ResultSet object like, the number of columns, names of the columns, datatypes of the columns, name of the table etc…Following are some methods of ResultSetMetaData class.MethodDescriptiongetColumnCount()Retrieves the number of columns in the current ResultSet object.getColumnLabel()Retrieves the suggested name of the column for use.getColumnName()Retrieves the name of the column.getTableName()Retrieves the name of the table.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; public class ResultSetMetadataExample {    public static void main(String args[]) throws Exception {       //Registering the Driver       DriverManager.registerDriver(new com.mysql.jdbc.Driver());       //Getting the connection   ... Read More

What is DatabaseMetaData in JDBC? What is its significance?

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

2K+ Views

Generally, Data about data is known as metadata. The DatabaseMetaData interface provides methods to get information about the database you have connected with like, database name, database driver version, maximum column length etc...Following are some methods of DatabaseMetaData class.MethodDescriptiongetDriverName()Retrieves the name of the current JDBC drivergetDriverVersion()Retrieves the version of the current JDBC drivergetUserName()Retrieves the user name.getDatabaseProductName()Retrieves the name of the current database.getDatabaseProductVersion()Retrieves the version of the current database.getNumericFunctions()Retrieves the list of the numeric functions available with this database.getStringFunctions()Retrieves the list of the numeric functions available with this database.getSystemFunctions()Retrieves the list of the system functions available with this database.getTimeDateFunctions()Retrieves the list ... Read More

How to retrieve particular columns of a table using JDBC program?

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

5K+ 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 first row.You can move the cursor using the next() method and, you can retrieve the column values of a row using the getter methods of the ResultSet interface (getInt(), getString(), getDate() etc..).To retrieve required data from a table:Connect to the database.Create a Statement object.Execute the Statement using the executeQuery() method. To this method, pass the select query in the String format. To retrieve all the values, we use the following query:Select ... Read More

What is Result in JDBC? How to retrieve data from ResultSet object?

Daniol Thomas
Updated on 09-Mar-2020 06:31:58

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.Moving the pointer throughout result setThe next() method of the ResultSet interface moves the pointer of the current (ResultSet) object to the next row, from the current position. This method returns a boolean value, if there are no rows next to its current position it returns false, else it returns true. Therefore, using this method in the while loop you can iterate the contents of the result set.while(rs.next()){ }Getting the ... Read More

What are the differences between Stored procedures and functions?

Daniol Thomas
Updated on 01-Nov-2023 13:32:08

34K+ Views

Following are the main differences between functions and procedures:FunctionsProceduresA function has a return type and returns a value.A procedure does not have a return type. But it returns values using the OUT parameters.You cannot use a function with Data Manipulation queries. Only Select queries are allowed in functions.You can use DML queries such as insert, update, select etc… with procedures.A function does not allow output parametersA procedure allows both input and output parameters.You cannot manage transactions inside a function.You can manage transactions inside a procedure.You cannot call stored procedures from a functionYou can call a function from a stored procedure.You ... Read More

Can we call functions using Callable Statements? Explain with an example in JDBC?

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

2K+ Views

Like procedures, you can also create function in a database and store them.SyntaxFollowing is the syntax of creating a function in a(MySQL) database:CREATE FUNCTION Function_Name(input_arguments) RETURNS output_parameter BEGIN    declare variables;    statements . . . . . . . . . .    return data_type;    ENDExampleSuppose we have a table named Emp in the database with the following content:+--------+------------+----------------+ | Name   | DOB        | Location      | +--------+------------+----------------+ | Amit   | 1970-01-08 | Hyderabad      | | Sumith | 1970-01-08 | Vishakhapatnam | | Sudha  | 1970-01-05 | Vijayawada     ... Read More

Advertisements