Check How Many Rows Are in a MySQL Database Table

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

1K+ Views

To know how many rows are in a ySQL database table, you need to use aggregate function COUNT(*).The syntax is as followsSELECT COUNT(*) FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table CountRowsDemo    - > (    - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > Name varchar(20)    - > ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into CountRowsDemo(Name) values(NULL); Query OK, 1 row affected (0.15 sec) mysql> ... Read More

How Cookies Work in JSP

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

279 Views

Cookies are usually set in an HTTP header (although JavaScript can also set a cookie directly on a browser). A JSP that sets a cookie might send headers that look something like this −HTTP/1.1 200 OK Date: Fri, 04 Feb 2000 21:03:38 GMT Server: Apache/1.3.9 (UNIX) PHP/4.0b3 Set-Cookie: name = xyz; expires = Friday, 04-Feb-07 22:03:38 GMT; path = /; domain = tutorialspoint.com Connection: close Content-Type: text/htmlAs you can see, the Set-Cookie header contains a name value pair, a GMT date, a path and a domain. The name and value will be URL encoded. The expires field is an instruction ... Read More

Use Length in Android TextView

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

946 Views

This example demonstrate about How to use length () in Android textview.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 the name as Edit text, when user click on button it will take data and check length of entered value is 0 or more than zero than returns last index of “sai”.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; ... Read More

IntStream forEach Method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

476 Views

The forEach() method is used in Java to perform an action for each element of this stream. Display the stream using the forEach() method in Java IntStreamThe syntax is as followsvoid forEach(IntConsumer action)Here, action is a non-interfering action to perform on the elements.Create IntStream and add elementsIntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);Now, display the streamintStream.forEach(System.out::println);The following is an example to implement IntStream forEach() method in JavaExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.of(15, 30, 40, 60, 75, 90);       intStream.forEach(System.out::println); ... Read More

Ennead Class in JavaTuples

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

116 Views

An Ennead class is a Tuple of 9 elements. It is in the JavaTuples library. The following is the declaration of the Ennead classpublic final class Ennead extends Tuple implements IValue0, IValue1, IValue2, IValue3, IValue4, IValue5, IValue6, IValue7, IValue8Let us first see what we need to work with JavaTuples. To work with Ennead class in JavaTuples, you need to import the following packageimport org.javatuples.Ennead;Note − Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. ... Read More

MongoDB Query with OR Condition

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

471 Views

To understand the query with an or condition, let us create a collection with the document. The query to create a collection with a document is as follows −> db.orConditionDemo.insertOne({"CustomerName":"Larry", "ShippingDate":new ISODate("2018-01-29")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec5262f684a30fbdfd56a") } > db.orConditionDemo.insertOne({"CustomerName":"Mike", "ShippingDate":new ISODate("2019-04-13")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec5362f684a30fbdfd56b") } > db.orConditionDemo.insertOne({"CustomerName":"Bob", "ShippingDate":new ISODate("2019-02-21")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec5422f684a30fbdfd56c") } > db.orConditionDemo.insertOne({"CustomerName":"David", "ShippingDate":new ISODate("2019-03-15")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec5532f684a30fbdfd56d") } > db.orConditionDemo.insertOne({"CustomerName":"John", "ShippingDate":new ISODate("2019-03-19")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ec56c2f684a30fbdfd56e") }Display all documents ... Read More

Convert Date Object to Timestamp in JDBC Program

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

717 Views

The getTime() method of the java.sql.Date class retrieves and returns the time from the current timestamp in milliseconds (long) from epoch time 1, 1970 00:00:00.000 GMT.//Retrieving the date Date date = rs.getDate("Dispatch_Date");The constructor of the java.sql.Timestamp class accepts a long variable representing the time in milliseconds from the epoch time and constructs the Timestamp object.//Creating a Timestamp object. Timestamp ts = new Timestamp(date.getTime()));Using these, you can convert a Date object to TimeStamp object in JDBC.Assume we have established connection with MySQL database and created a table named dispatch_data using statement object as:Assume we have established connection with MySQL database and ... Read More

Remove Document by ID in MongoDB

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

232 Views

To remove document on the basis of _id in MongoDB, implement the following syntaxdb.yourCollectionName.remove({“_id”:ObjectId(“yourId”});Let us first implement the following query to create a collection with documents>db.removeDocumentOnBasisOfId.insertOne({"UserName":"Larry", "UserAge":23, "UserCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986f9f330fd0aa0d2fe4a3") } >db.removeDocumentOnBasisOfId.insertOne({"UserName":"Sam", "UserAge":21, "UserCountryName":"UK"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986fb4330fd0aa0d2fe4a4") } >db.removeDocumentOnBasisOfId.insertOne({"UserName":"Chris", "UserAge":24, "UserCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986fc0330fd0aa0d2fe4a5") } >db.removeDocumentOnBasisOfId.insertOne({"UserName":"Robert", "UserAge":26, "UserCountryName":"UK"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986fcf330fd0aa0d2fe4a6") } >db.removeDocumentOnBasisOfId.insertOne({"UserName":"David", "UserAge":28, "UserCountryName":"AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986fed330fd0aa0d2fe4a7") }Following is the query to display all documents from a collection ... Read More

Meaning of AUTO_INCREMENT in MySQL Schema

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

305 Views

In MySQL, AUTO_INCREMENT=3 tells that the inserted record will start from 3 not the default 1. Let us first create a sample table and set auto increment to 3:mysql> create table Auto_incrementDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> )AUTO_INCREMENT=3; Query OK, 0 rows affected (0.52 sec)Following is the query to insert some records in the table using insert command:mysql> INSERT INTO Auto_incrementDemo(Name) values('John'); Query OK, 1 row affected (0.12 sec) mysql> INSERT INTO Auto_incrementDemo(Name) values('Larry'); Query OK, 1 row affected (0.15 sec) mysql> INSERT INTO Auto_incrementDemo(Name) ... Read More

Convert Java Util Date to Local Date in Any Timezone

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

214 Views

First, set the Date and ZoneId −Date date = new Date(); ZoneId zone = ZoneId.systemDefault();Now convert the java.util.date to localdate −date.toInstant().atZone(zone).toLocalDate() date.toInstant().atZone(zone).toLocalTime() date.toInstant().atZone(zone).getHour() date.toInstant().atZone(zone).getMinute() date.toInstant().atZone(zone).getSecond()Exampleimport java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       Date date = new Date();       ZoneId zone = ZoneId.systemDefault();       System.out.println("LocalDate = "+date.toInstant().atZone(zone).toLocalDate());       System.out.println("LocalTime= "+date.toInstant().atZone(zone).toLocalTime());       System.out.println("Hour = "+date.toInstant().atZone(zone).getHour());       System.out.println("Minute = "+date.toInstant().atZone(zone).getMinute());       System.out.println("Seconds = "+date.toInstant().atZone(zone).getSecond());    } }OutputLocalDate = 2019-04-18 LocalTime= 23:25:09.708 Hour = 23 Minute = 25 Seconds = 9Read More

Advertisements