Programming Articles - Page 2726 of 3366

Catching base and derived classes exceptions in C++

Revathi Satya Kondra
Updated on 07-May-2025 14:33:33

2K+ Views

To catch an exception for both base and derived classes, we need to put the catch block of the derived class before the base class. Otherwise, the catch block for the derived class will never be reached. This happens because C++ follows a top-down approach when checking catch blocks. So, by placing the derived class catch block first, we ensure that specific exceptions are handled correctly before falling back on the base class. Algorithm Following is the algorithm to catch Base and Derived classes Exceptions in C++: Begin Declare a class B. Declare another ... Read More

How to get the number of records in a table using JDBC?

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

503 Views

The ResultSet class doesn’t provide any direct method to get the number of records in a table.The beforeFirst() method navigates the pointer/curser of the ResultSet object to its default position before first.In the same way the last() method positions the cursor at the last row of the ResultSet object.Using these methods you can find the number of records in the current ResultSet object.ExampleAssume we have a table named customers table with contents as shown below:+----+---------+-----+---------+----------------+ | ID | NAME    | AGE | SALARY  | ADDRESS        | +----+---------+-----+---------+----------------+ | 1  | Amit    | 25  | 3000.00 ... Read More

How to declare a pointer to a function in C?

Revathi Satya Kondra
Updated on 06-May-2025 18:53:52

6K+ Views

In C, a pointer is a variable whose value is the address of another variable or memory block, i.e direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable or block address. Basic Pointer to a Function A pointer to a function is simply a variable that stores the address of a function instead of a normal data value. Syntax Following is the syntax of basic pointer to a function: Datatype *variable_name Algorithm Following is the algorithm for the basic pointer to a Function: Begin. ... Read More

The contains() method of Java AbstractCollection class

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

130 Views

The contains() method of the AbstractCollection class checks whether an element is in the AbstractCollection or not. It returns a Boolean i.e. TRUE if the element is in the collection, else FALSE is returned.The syntax is as follows:public boolean contains(Object ele)Here, ele is the element to be checked for existence.To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;The following is an example to implement AbstractCollection contains() method in Java:Example Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("Football");   ... Read More

How to create and release a save point in JDBC?

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

980 Views

When you set a save point you define a logical rollback point within a transaction. If an error occurs past a save point, you can use the rollback method to undo either all the changes or only the changes made after the save point.Savepoint interface gives you the additional transactional control. Most modern DBMS, support save points within their environments such as Oracle's PL/SQL.Setting a save pointYou can set a save point in a database using the setSavepoint(String savepointName) method of the Connection interface, this method accepts a string value representing the name of the save point and returns a ... Read More

The clear() method of Java AbstractCollection class

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

194 Views

The clear() method of the AbstractCollection class is used to remove all the elements from this collection. This makes the collection empty.The syntax is as follows:public void clear()To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;First, create AbstractCollection and add some elements using the add() method:AbstractCollection absCollection = new ArrayList(); absCollection.add("These"); absCollection.add("are"); absCollection.add("demo"); absCollection.add("elements");Now, clear the AbstractCollection:absCollection.clear();The following is an example to implement AbstractCollection clear() method in Java:Example Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("These");     ... Read More

The addAll() method of Java AbstractCollection class

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

121 Views

The addAll() method of the AbstractCollection class in Java is used to add all of elements in the specified collection to this collection. It returns TRUE if the elements are successfully appendedThe syntax is as follows:public boolean addAll(Collection

How to set/insert null values to in to a column of a row using JDBC program?

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

7K+ Views

You can insert null values into a table in SQL in two ways:Directly inserting the value NULL into the desired column as:Insert into SampleTable values (NULL);Using ‘ ’ as nullInsert into SampleTable values (NULL);While inserting data into a table using prepared statement object you can set null values to a column using the setNull() method of the PreparedStatement interface.pstmt.setNull(parameterIndex, sqlType);ExampleAssume we have a table named cricketers_data in the database with the following contents:+------------+------------+---------------+----------------+-------------+ | First_Name | Last_Name  | Date_Of_Birth | Place_Of_Birth | Country | +------------+------------+---------------+----------------+-------------+ | Shikhar    | Dhawan     | 1981-12-05    | ... Read More

The hashCode() method of AbstractList class in Java

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

108 Views

The hashCode() method of AbstractList class returns the hash code value for this list.The syntax is as follows:public int hashCode()To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement hashCode() method of the AbstractlList class in Java:Example Live Demoimport java.util.ArrayList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new ArrayList();       myList.add(50);       myList.add(100);       myList.add(150);       myList.add(200);       myList.add(250);       myList.add(300);       myList.add(350);       myList.add(400);   ... Read More

The set() method of AbstractList class in Java

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

109 Views

The set() method of the AbstractList class is used to replace the element at the specified position in this list with the specified element. It returns the element that gets replaced.The syntax is as follows:public E set(int index, E ele)Here, the parameter index is the index of the element to replace, whereas ele is the element to be stored at the specified position.To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement set() method of the AbstractlList class in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] ... Read More

Advertisements