Search DOB in MySQL Table with YYYY-MM-DD Structure

AmitDiwan
Updated on 08-Jul-2020 08:08:15

156 Views

For this, use MySQL YEAR() as in the below syntax −select * from yourTableName where year(yourColumnName)=’yourYearValue’;Let us first create a table −mysql> create table DemoTable1322 -> ( -> DOB date -> ); Query OK, 0 rows affected (0.55 sec)ExampleInsert some records in the table using insert command −mysql> insert into DemoTable1322 values('1999-04-12'); Query OK, 1 row affected (0.68 sec) mysql> insert into DemoTable1322 values('2010-12-01'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1322 values('2015-03-09'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable1322 values('2007-05-24'); Query OK, 1 row affected (0.08 sec)Display all records from the table ... Read More

Anchor Pseudo-Classes in CSS

AmitDiwan
Updated on 08-Jul-2020 07:38:48

1K+ Views

Using CSS pseudo-class selectors, namely, :active, :hover, :link and :visited we can style different states of a link/anchor. For proper functionality, the order of these selectors should be −:link:visited:hover:activeThe syntax of CSS psudo-class property is as follows −a:(pseudo-selector) {    /*declarations*/ }ExampleLet’s see an example to use CSS Anchor Pseudo Classes − Live Demo div {    display: flex;    float: left; } a {    margin: 20px;    padding: 10px;    border: 2px solid black;    text-shadow: -1px 0px black, 0px -1px black, 0px 1px black, 1px 0px black;    font-size: 1.1em; } a:link {    text-decoration: ... Read More

Find Final X and Y Values in C++ Under Given Conditions

Arnab Chakraborty
Updated on 08-Jul-2020 07:33:12

117 Views

Consider we have the initial values of two positive integers X and Y. Find the final value of X and Y, such that there will be some alteration as mentioned below −step1 − If X = 0 and Y = 0 then terminate the process, otherwise go to step2step2 − If X >= 2Y, then set X = X – 2Y, and go to step1, otherwise go to step3step3 − If Y >= 2X, then set Y = Y – 2X, and go to step1, otherwise end the process.The number X and Y will be in range [0 and 1018] ... Read More

Add Elements to JSON Object Using JSON-lib API in Java

raja
Updated on 08-Jul-2020 07:31:03

3K+ Views

The JSON-lib is a Java library for serializing and de-serializing java beans, maps, arrays, and collections in JSON format. We can add elements to the JSON object using the element() method of JSONObject class. We need to download all the dependent jars like json-lib.jar, ezmorph.jar, commons-lang.jar, commons-collections.jar, commons-beanutils.jar, and commons-logging.jar and can import net.sf.json package in our java program to execute it.Syntaxpublic JSONObject element(String key, Object value) - put a key/value pair in the JSONObject Exampleimport java.util.Arrays; import net.sf.json.JSONObject; public class JsonAddElementTest {    public static void main(String[] args) {       JSONObject jsonObj = new JSONObject()          .element("name", "Raja ... Read More

Convert Collection to JSON Array Using JSON-lib API in Java

raja
Updated on 08-Jul-2020 07:30:31

899 Views

The net.sf.json.JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas separating the values and an internal form is an object having get() and opt() methods for accessing the values by index, and element() method for adding or replacing values. The values can be any of these types like Boolean, JSONArray, JSONObject, Number, String and JSONNull object.We can convert a collection(List) to JSON array in the below exampleExampleimport java.util.*; import net.sf.json.JSONArray; import net.sf.json.JSONSerializer; public class ConvertCollectionToJsonArrayTest {    public static void main(String[] args) {       List strList = Arrays.asList("India", "Australia", "England", ... Read More

Serialize and Deserialize JSON Using ExclusionStrategy Interface in Java

raja
Updated on 08-Jul-2020 06:48:57

732 Views

The ExclusionStrategy interface can be used to exclude any field during serialization and deserialization. We can provide a custom implementation of the ExclusionStrategy interface and need to register it with GsonBuilder using the setExclusionStrategies() method. It configures Gson to apply a set of exclusion strategies during serialization and deserialization.Syntaxpublic GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies)Exampleimport com.google.gson.*; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; public class ExclusionStrategyTest {    public static void main(String args[]) throws Exception {       Gson gson = new GsonBuilder().setExclusionStrategies(new CustomExclusionStrategy()).create();          Person person = new Person();          person.setFirstName("Adithya");          person.setLastName("Sai");          person.setAddress("Hyderabad");     ... Read More

Update Existing JSON Data Using javax.json API in Java

raja
Updated on 08-Jul-2020 06:48:13

7K+ Views

The JsonBuilderFactory interface is a factory to create JsonObjectBuilder instance and JsonObjectBuilder is a builder for creating JsonObject models from scratch. This interface initializes an empty JSON object model and provides methods to add name/value pairs to the object model and to return the resulting object. We can create a JsonObjectBuilder instance that can be used to build JsonObject using the createObjectBuilder() method.SyntaxJsonObjectBuilder createObjectBuilder()In the below example, We can update an existing JSON data with newly added data.Exampleimport java.io.*; import javax.json.*; public class UpdateExistingJsonTest {    public static void main(String[] args) throws Exception {       String jsonString = "{\"id\":\"115\", \"name\":\"Raja\", \"address\":[{\"area\":\"Madhapur\", \"city\":\"Hyderabad\"}]}";       ... Read More

JSON Schema Support Using Jackson in Java

raja
Updated on 08-Jul-2020 06:46:35

5K+ Views

JSON Schema is a specification for JSON based format for defining the structure of JSON data. The JsonSchema class can provide a contract for what JSON data is required for a given application and how to interact with it. The JsonSchema can define validation, documentation, hyperlink navigation, and interaction control of JSON data. We can generate the JSON schema using the generateSchema() method of JsonSchemaGenerator, this class wraps the JSON schema generation functionality.Syntaxpublic JsonSchema generateSchema(Class type) throws com.fasterxml.jackson.databind.JsonMappingExceptionExampleimport com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jsonSchema.JsonSchema; import com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator; import java.util.List; public class JSONSchemaTest {    public static void main(String[] args) throws JsonProcessingException {     ... Read More

Check if a Bluetooth Device is Connected with Android Device

Azhar
Updated on 08-Jul-2020 06:22:24

3K+ Views

This example demonstrates how do I check if a Bluetooth device is connected with android device.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.     Step 3 − Add the following code to src/MainActivity.javaimport android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);     ... Read More

Get Free Size of Internal & External Memory in Android App

Azhar
Updated on 08-Jul-2020 06:21:44

1K+ Views

This example demonstrates how do I get the free size of internal/external memory in android app.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.     Step 3 − Add the following code to src/MainActivity.javaimport android.os.Bundle; import android.os.Environment; import android.os.StatFs; import android.util.Log; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       ... Read More

Advertisements