Use AVG Function in Android SQLite

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

231 Views

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

Period Between Method in Java

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

4K+ Views

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

Calculate Average of Values in a Row using MySQL Query

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

371 Views

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

Query with Values Prepended by Ampersand in Oracle vs MySQL

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

122 Views

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

Move Pointer of ResultSet to End of Table Using JDBC

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

135 Views

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

Find and Modify a Value in a Nested Array

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

223 Views

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

Generate Random Booleans in Java

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

347 Views

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

Insert Records into Two Tables at Once Using Stored Procedure in MySQL

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

499 Views

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

ConcurrentSkipListSet in Java

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

280 Views

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

Java Signature getProvider Method

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

195 Views

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

Advertisements