Found 317 Articles for JDBC

How to move the pointer of a ResultSet to the end of the table using JDBC?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

83 Views

The afterLast() method of the ResultSet interface moves the cursor/pointer after the last row of the ResultSet object.rs.afterLast();Assume we have a table name dataset as shown below:+--------------+-----------+ | mobile_brand | unit_sale | +--------------+-----------+ | Iphone       | 3000      | | Samsung      | 4000      | | Nokia        | 5000      | | Vivo         | 1500      | | Oppo         | 900       | | MI           | 6400      | | MotoG   ... Read More

How to move the pointer of a ResultSet to the default position using JDBC?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

467 Views

The beofreFirst() method of the ResultSet interface moves the cursor/pointer to its default position i.e. before the first record.rs.beforeFirst();Assume we have a table named cricketers_data with 6 records as shown below:+----+------------+------------+---------------+----------------+-------------+ | ID | First_Name | Last_Name  | Year_Of_Birth | Place_Of_Birth | Country     | +----+------------+------------+---------------+----------------+-------------+ | 1 | Shikhar     | Dhawan     | 1981-12-05    | Delhi          | India       | | 2 | Jonathan    | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | 3 | Lumara      | Sangakkara ... Read More

How to insert a row into a ResultSet object using JDBC?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

324 Views

The insertRow() method of the ResultSet interface inserts a new row into the ResultSet object as well as the table.//Deleting a column from the ResultSet object rs.insertRow();Assume we have a table named cricketers_data with 6 records as shown below:+----+------------+------------+---------------+----------------+-------------+ | ID | First_Name | Last_Name  | Year_Of_Birth | Place_Of_Birth | Country     | +----+------------+------------+---------------+----------------+-------------+ | 1  | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India       | | 2  | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | ... Read More

How to find the current row of a ResultSet object using JDBC?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

543 Views

The getRow() method of the ResultSet class returns the row number at which the ResultSet pointer exists in the current instance.Assume we have a table named cricketers_data with 6 records as shown below:+------------+------------+---------------+----------------+-------------+ | First_Name | Last_Name  | Date_Of_Birth | Place_Of_Birth | Country     | +------------+------------+---------------+----------------+-------------+ | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India       | | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | Lumara     | Sangakkara | 1977-10-27    | Matale     ... Read More

How to move the result set pointer to required position?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

182 Views

The absolute() method of the ResultSet interface accepts an integer value representing the index of a row and moves the ResultSet pointer of the current ResultSet object to the specified position.Assume we have a table named cricketers_data with 6 records as shown below:+------------+------------+---------------+----------------+-------------+ | First_Name | Last_Name  | Date_Of_Birth | Place_Of_Birth | Country     | +------------+------------+---------------+----------------+-------------+ | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India       | | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | Lumara   ... Read More

How to delete a row from ResultSet object using JDBC?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

852 Views

The deleteRow() method of the ResultSet interface deletes the current row from the current ResultSet object.//Deleting a column from the ResultSet object rs.deleteRow();Assume we have a table named Cricketers_Data with 6 records as shown below:+----+------------+------------+---------------+----------------+-------------+ | ID | First_Name | Last_Name  | Year_Of_Birth | Place_Of_Birth | Country     | +----+------------+------------+---------------+----------------+-------------+ | 1  | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India | | 2  | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | 3 ... Read More

How to create a table in JDBC using another table?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

348 Views

You can create a table same as an existing table using the following syntax:CREATE TABLE new_table as SELECT * from old_table;Assume we have a table named dispatches with 5 records as shown below:+-------------+--------------+--------------+--------------+-------+----------------+ | ProductName | CustomerName | DispatchDate | DeliveryTime | Price | Location       | +-------------+--------------+--------------+--------------+-------+----------------+ | Key-Board   | Raja         | 2019-09-01   | 05:30:00     | 7000  | Hyderabad     | | Earphones   | Roja         | 2019-05-01   | 05:30:00     | 2000  | Vishakhapatnam | | Mouse       ... Read More

How to get the number of columns of a table using JDBC?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

666 Views

You can get the number of columns of a table using the getColumnCount() method of the ResultSetMetaData class.//Retrieving the ResultSetMetaData object ResultSetMetaData rsmd = rs.getMetaData(); //getting the column type int column_count = rsmd.getColumnCount();Assume we have a table named employee_data in the database with description as shown below:+----------+--------------+------+-----+---------+-------+ | Field    | Type         | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id       | int(11)      | YES  |     | NULL    |       | | Name     | varchar(255) | YES  |     ... Read More

How to get the size of a column of a table using JDBC?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

1K+ Views

You can get the size of a column of a table using the getPrecision() method of the ResultSetMetaData class.//Retrieving the ResultSetMetaData object ResultSetMetaData rsmd = rs.getMetaData(); //getting the column type int size_name = rsmd. getPrecision(3);Assume we have a table named employee_data in the database with description as shown below:+----------+--------------+------+-----+---------+-------+ | Field    | Type         | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id       | int(11)      | YES  |     | NULL    |       | | Name     | varchar(255) | YES  | ... Read More

How to get the datatype of a column of a table using JDBC?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

3K+ Views

You can get the datatype of a column of a table using the getColumnType() method of the ResultSetMetaData class.//Retrieving the ResultSetMetaData object ResultSetMetaData rsmd = rs.getMetaData(); //getting the column type String column_name = rsmd.getColumnTypeName(2);Assume we have a table named employee_data in the database with the description as shown below:+----------+--------------+------+-----+---------+-------+ | Field    | Type         | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id       | int(11)      | YES  |     | NULL    | | | Name     | varchar(255) ... Read More

Advertisements