JSP gives you an option to specify Error Page for each JSP using page attribute. Whenever the page throws an exception, the JSP container automatically invokes the error page.Following is an example to specifiy an error page for a main.jsp. To set up an error page, use the directive. Error Handling Example We will now write one Error Handling JSP ShowError.jsp, which is given below. Notice that the error-handling page includes the directive . This directive causes the JSP compiler ... Read More
Timestamp datatype in SQL is similar to Date (in SQL) both store day:month:year:hour:minute:second. In addition to this timestamp stores fractional seconds too.Inserting Timestamp in to a databaseThe PreparedStatement interface provides a method named setTimestamp() this method accepts two parameters an integer variable representing the parameter index of the place holder at which you need to store the timestamp and a long variable representing the number of milliseconds from the epoch time(standard base time I.e. January 1, 1970, 00:00:00 GMT) to the required time.ExampleAssume we have a table in the database named dispatches with the following description −+------------------+--------------+------+-----+-------------------+ | Field ... Read More
A LabelValue class is a Tuple of 2 elements with label as the first position, whereas value as the second. It is in the JavaTuples library. The LabelValue Tuple class is Typesafe, Immutable, Iterable, Serializable, etc.The following is the declaration of the LabelValue class;public final class LabelValue extends Tuple implements IValueLabel, IValueValueLet us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following packageimport org.javatuples.LabelValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path ... Read More
The Period instance can be obtained from a string value using the parse() method in the Period class in Java. This method requires a single parameter i.e. the string which is to be parsed. This string cannot be null. Also, it returns the Period instance obtained from the string value that was passed as a parameter.A program that demonstrates this is given as follows:Example Live Demoimport java.time.Period; public class Demo { public static void main(String[] args) { String period = "P5Y7M15D"; Period p = Period.parse(period); System.out.println("The Period is: " + p); ... Read More
Use DateTime to convert PHP variable “11:00 AM: to MySQL time format.The PHP code is as follows −$phpTime = '11:00 AM'; echo('The PHP Time Format is ='); echo ($phpTime); $timeFormat = DateTime::createFromFormat( 'H:i A', $phpTime); $MySQLTimeFormat = $timeFormat->format( 'H:i:s'); echo (' '); echo('The MySQL Time Format is ='); echo ($MySQLTimeFormat);The snapshot of PHP code is as follows −Here is the output −The PHP Time Format is =11:00 AM The MySQL Time Format is =11:00:00
The AbstractSequentialList class has the add(int index, E ele) method to add element to the specific position. You can also use the add() method inherited from AbstractList class.add(int index, E ele) methodThe syntax is as follows:add(int index, E ele)Here, index is where the element is to be inserted. The ele is the element to be inserted.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 add() method in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { ... Read More
To find all documents with a field that is NAN in MongoDB, use the following syntaxdb.yourCollectionName.find( { yourFieldName: NaN })Let us first create a collection with documents> db.nanDemo.insertOne({"Score":0/0}); { "acknowledged" : true, "insertedId" : ObjectId("5ca251a26304881c5ce84b8a") } > db.nanDemo.insertOne({"Score":10/5}); { "acknowledged" : true, "insertedId" : ObjectId("5ca2520e6304881c5ce84b8b") } > db.nanDemo.insertOne({"Score":20/0}); { "acknowledged" : true, "insertedId" : ObjectId("5ca252156304881c5ce84b8c") } > db.nanDemo.insertOne({"Score":0/20}); { "acknowledged" : true, "insertedId" : ObjectId("5ca2521e6304881c5ce84b8d") }Following is the query to display all documents from a collection with the help of find() method> db.nanDemo.find().pretty();This will produce the following output{ "_id" : ObjectId("5ca251a26304881c5ce84b8a"), "Score" ... Read More
We will first set a list to unmodifiable and after that test if it is unmodifiable or not. Let us create a List and add elements −List list = new LinkedList (); list.add(10); list.add(20); list.add(30); list.add(40); list.add(50);Set the above list to unmodifiable −Listunmodifiable = Collections.unmodifiableList(list);Now, use If-else, to check whether the list in unmodifiable or not −if (unmodifiable.getClass().getName().contains("UnmodifiableList")) System.out.println("This is an UnmodifiableList" ); else System.out.println("This is not an UnmodifiableList" );Example Live Demoimport java.util.Collections; import java.util.LinkedList; import java.util.List; public class Demo { public static void main(String[] args) { Listlist = new LinkedList(); ... Read More
Use CAST() in MAX() to get max id from varchar type and values in numeric. Let us first create a table. Here, we have a column with varchar type −mysql> create table DemoTable ( UserMarks varchar(20) ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('77'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('98'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('45'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('56'); Query OK, 1 row affected (0.18 ... Read More
The ConcurrentLinkedDeque Class in Java implements a deque and used a concurrent linked list for help. This class implements the Collection interface as well as the AbstractCollection class. It is a part of the Java Collection Framework.A program that demonstrates this is given as follows −Example Live Demoimport java.util.concurrent.*; public class Demo { public static void main(String[] args) { ConcurrentLinkedDeque clDeque = new ConcurrentLinkedDeque(); clDeque.add("James"); clDeque.add("May"); clDeque.add("John"); clDeque.add("Sara"); clDeque.add("Anne"); System.out.println("The elements in ConcurrentLinkedDeque are: " + clDeque); } ... Read More