Before getting into an example, we should know what SQLite database in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built-in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrates How to use AVG () in Android SQLite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a ... Read More
The Period between two dates can be obtained using the between() method in the Period class in Java. This method requires two parameters i.e. the start date and the end date and it returns the Period between these two dates.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; import java.time.LocalDate; public class Demo { public static void main(String[] args) { LocalDate startDate = LocalDate.parse("2015-03-15"); LocalDate endDate = LocalDate.parse("2019-05-20"); System.out.println("The start date is: " + startDate); System.out.println("The end date is: " + endDate); ... Read More
To calculate the average of values in a row in MySQL, use the following syntaxSELECT (yourTableName.yourColumnName1+yourTableName.yourColumnName2+yourTableName.yourColumnName3+, ..........N)/numberOfColumns AS anyAliasName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table calculateAverageDemo -> ( -> x int, -> y int, -> z int -> ); Query OK, 0 rows affected (1.41 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into calculateAverageDemo values(10, 20, 30); Query OK, 1 row affected (0.78 sec) mysql> insert into calculateAverageDemo values(40, 50, 70); Query ... Read More
Ampersands work in Oracle. To work it in MySQL, use @ as shown in the following syntax −SET @yourVariableName1 = yourValue, @yourVariableName2 = yourValue, @yourVariableName3 =yourValue, .........N; insert into yourTableName values(@yourVariableName1, @yourVariableName2, @yourVariableName3, ........N);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Student_Information -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int, -> StudentMarks int, -> StudentCountryName varchar(10) -> ); Query OK, 0 rows affected (0.75 sec)Here is the query with values prepended by @. Insert some records ... Read More
The afterLast() method of the ResultSet interface moves the cursor/pointer after the last row of the ResultSet object.rs.afterLast();Assume we have a table name dataset as shown below:+--------------+-----------+ | mobile_brand | unit_sale | +--------------+-----------+ | Iphone | 3000 | | Samsung | 4000 | | Nokia | 5000 | | Vivo | 1500 | | Oppo | 900 | | MI | 6400 | | MotoG ... Read More
To find and modify a value in a nested array, you can use update command. Let us first create a collection with documents> db.findAndModifyAValueInNestedArrayDemo.insertOne( { "CompanyName" : "Amazon", "DeveloperDetails" : [ { "ProjectName" : "Online Book Store", "TeamSize" : "5" }, { "ProjectName" : "Library Management System", "TeamSize" : "7" }, { "ProjectName" : "Online Banking Application", "TeamSize" : "15" } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5ca275226304881c5ce84b9f") }Following is the query to display all documents from a collection with the help of find() method> db.findAndModifyAValueInNestedArrayDemo.find().pretty();This will produce the following output{ "_id" : ObjectId("5ca275226304881c5ce84b9f"), ... Read More
To generate random booleans like TRUE or FALSE, at first create a new Random object −Random randNum = new Random();Now, loop through the count of booleans you want and generate random booleans with nextBooleans() method −for (int i = 1; i
Yes, you can use stored procedure to insert into two tables in a single query. Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(20) ); Query OK, 0 rows affected (0.56 sec)Here is the query to create second table −mysql> create table DemoTable2 ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(20), ClientAge int ); Query OK, 0 rows affected (0.76 sec)Following is the query to create stored procedure to insert into two tables created above −mysql> DELIMITER // mysql> CREATE PROCEDURE ... Read More
The ConcurrentSkipListSet has elements that are sorted by default. Also, its implementation is based on the ConcurrentSkipListMap. The ConcurrentSkipListSet class also implements the Collection interface as well as the AbstractSet 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.ConcurrentSkipListSet; public class Demo { public static void main(String[] args) { ConcurrentSkipListSet csls = new ConcurrentSkipListSet(); csls.add(7); csls.add(4); csls.add(1); csls.add(9); csls.add(3); System.out.println("The elements in ConcurrentSkipListSet are: " + ... Read More
The provider for the signature object can be obtained using the method getProvider() in the class java.security.Signature. This method requires no parameters and it returns the provider for the signature object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo { public static void main(String[] argv) { try { Signature signature = Signature.getInstance("SHA256withRSA"); Provider provider = signature.getProvider(); System.out.println("The Provider is: " + provider); } catch (NoSuchAlgorithmException e) { ... Read More