Get Max ID from Varchar Type in MySQL

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

382 Views

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

ConcurrentLinkedDeque in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

100 Views

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

CharBuffer Allocate Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

158 Views

A new CharBuffer can be allocated using the method allocate() in the class java.nio.CharBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new CharBuffer that is allocated. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          CharBuffer buffer = CharBuffer.allocate(n);          buffer.put('A');          buffer.put('P');   ... Read More

Add String and Other Data Types for ListView in Android

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

743 Views

This example demonstrates How to add string and other data types for Listview in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/ activity_main.xml.                             In the above code, we have taken name and record number as Edit text, when user click on save button it will store the data into arraylist. Click on refresh ... Read More

Handle Error Object in JSP Using JSTL Tags

Chandu yadav
Updated on 30-Jul-2019 22:30:25

616 Views

You can make use of JSTL tags to write an error page ShowError.jsp with better structure and more information −           Show Error Page               Opps...                             Error:             ${pageContext.exception}                                 URI:             ${pageContext.errorData.requestURI}                             ... Read More

Set Data Source in a JSP

Samual Sam
Updated on 30-Jul-2019 22:30:25

615 Views

The tag sets the data source configuration variable or saves the data-source information in a scoped variable that can be used as input to the other JSTL database actions.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultdriverName of the JDBC driver class to be registeredNoNoneurlJDBC URL for the database connectionNoNoneuserDatabase usernameNoNonepasswordDatabase passwordNoNonepasswordDatabase passwordNoNonedataSourceDatabase prepared in advanceNoNonevarName of the variable to represent the databaseNoSet defaultscopeScope of the variable to represent the databaseNoPageExampleConsider the following information about your MySQL database setup −We are using JDBC MySQL driver.We are going to connect to TEST database on local machine.We would use user_id and my ... Read More

DoubleStream Parallel Method in Java

George John
Updated on 30-Jul-2019 22:30:25

155 Views

The parallel() method of the DoubleStream class returns an equivalent stream which is parallel.The syntax is as followsDoubleStream parallel()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream parallel() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(35.8, 14.9, 23.3, 67.8, 89.4, 45.6); System.out.println("Parallel DoubleStream = "); doubleStream.parallel().forEach(System.out::println); } }OutputParallel DoubleStream = 67.8 14.9 23.3 89.4 45.6 35.8

Period.from() Method in Java

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

129 Views

An instance of a Period object can be obtained from a Temporal object using the from() method in the Period class in Java. This method requires a single parameter i.e. the TemporalAmount and it returns the Period object that is obtained.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       int days = 20;       int months = 11;       int years = 3;       Period p = Period.from(Period.of(years, months, days));       System.out.println("The Period is: " + ... Read More

Avoid Null Result of SELECT MAX Rank from Empty Table

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

3K+ Views

You can use COALESCE() along with aggregate function MAX() for this.The syntax is as followsSELECT COALESCE(MAX(`yourColumnName`), 0) FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table avoidNullDemo    -> (    -> `rank` int    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into avoidNullDemo values(10); Query OK, 1 row affected (0.20 sec) mysql> insert into avoidNullDemo values(NULL); Query OK, 1 row affected (0.18 sec) mysql> insert into avoidNullDemo values(20); Query OK, 1 ... Read More

Query MySQL on the Current Week

George John
Updated on 30-Jul-2019 22:30:25

2K+ Views

To query MySQL on the current week, you can use YEARWEEK() function.The syntax is as followsSELECT *FROM yourTableName WHERE YEARWEEK(yourDateColumnName) = YEARWEEK(NOW());To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table currentWeekDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserPostDate date -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into currentWeekDemo(UserName, ... Read More

Advertisements