Found 4336 Articles for Java 8

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

Naveen Singh
Updated on 30-Jul-2019 22:30:25

6K+ 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

Naveen Singh
Updated on 30-Jul-2019 22:30:25

68 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

Naveen Singh
Updated on 30-Jul-2019 22:30:25

63 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

The get() method of AbstractList class in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

132 Views

The get() method of the AbstractList class is used to get the element at the specified position in the list. It returns the element at the position set as parameter.The syntax is as follows:public abstract E get(int index)Here, index is the index of the element to return.To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement get() method of the AbstractlList class in Java:Exampleimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new LinkedList();       myList.add(50);       ... Read More

How to add elements to AbstractList class in Java?

Naveen Singh
Updated on 30-Jul-2019 22:30:25

263 Views

To add elements to AbstractList class, the add() method is provided by the AbstractList class. The elemnt gets appended at the end of the list.The syntax is as follows:public boolean add(E ele)Here, the parameter ele is an element to be appended to this listTo work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to add elements to AbstractlList class in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new LinkedList();       myList.add(50);       myList.add(100);       ... Read More

What is AbstractList Class in Java?

Naveen Singh
Updated on 30-Jul-2019 22:30:25

516 Views

The AbstractList class provides an implementation of the List interface.For an unmodifiable listProgrammer needs to extend this class and provide implementations for the get(int) and size() methods.For a modifiable listProgrammer must override the set(int, E) method. If the list is variable-size the programmer must override the add(int, E) and remove(int) methods.The following is the syntax:public abstract class AbstractList extends AbstractCollection implements ListTo work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement AbstractList class:Example Live Demoimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList ... Read More

The removeAll() method of AbstractSequentialList in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

61 Views

The removeAll() is a method inherited from AbstractCollection class. It removes all the elements of this collection that are also contained in the specified collection.The syntax is as follows:public boolean removeAll(Collection c)Here, the parameter c is the collection having elements to be removed from this collection.To work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList removeAll() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {      public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();       absSequential.add(210); ... Read More

The containsAll() method of AbstractSequentialList in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

60 Views

The containsAll() method of the AbstractSequentialList checks for all the elements in this collection. It returns TRUE if all this collection contains all the elements in the specified collection i.e. if the two collections are same.The syntax is as follows:public boolean containsAll(Collection c)Here, c is the collection to be checkedTo work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList containsAll() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();   ... Read More

The toArray(T[]) method of AbstractSequentialList in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

154 Views

The difference between toArray() and toArray(T[] arr) is that both the methods returns an array containing all of the elements in this collection, but the latter has some additional features i.e. the runtime type of the returned array is that of the specified array.The syntax is as follows:public T[] toArray(T[] arr)Here, arr is the array into which the elements of this collection are to be stored, To work with the AbstractSequentialList class in Java, you need to import the following package:import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList toArray() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class ... Read More

How to set auto-increment to an existing column in a table using JDBC API?

Naveen Singh
Updated on 30-Jul-2019 22:30:25

514 Views

You can add/set an auto increment constraint to a column in a table using the ALTER TABLE command.SyntaxALTER TABLE table_name ADD id INT PRIMARY KEY AUTO_INCREMENTAssume we have a table named Dispatches in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location with description as shown below:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  | UNI | NULL    | | | CustomerName | varchar(255) | YES  |     ... Read More

Advertisements