Found 4332 Articles for Java 8

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

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

679 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

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

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

365 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

The contains() method of Java AbstractCollection class

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

79 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

742 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

126 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

83 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

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

Daniol Thomas
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

Advertisements