Convert Java Object to JSON Using Gson Library

Maruthi Krishna
Updated on 10-Oct-2019 06:35:44

2K+ Views

JSON or JavaScript Object Notation is a lightweight text-based open standard designed for human-readable data interchange. Conventions used by JSON are known to programmers, which include C, C++, Java, Python, Perl, etc.There are several Java libraries available to handle JSON objects. Google Gson is a simple Java-based library to serialize Java objects to JSON and vice versa. It is an open-source library developed by Google.Converting Java object to JSONThe Google's Gson library provides a class with the same name (Gson) which is the main class of the library.This class provides a method named toJson() there are several variants of this ... Read More

Convert String to Character Array in Java

Maruthi Krishna
Updated on 10-Oct-2019 06:32:04

331 Views

You can convert a String to a character array either by copying each element of the String to an array or, using the toCharArray() method.Copying each elementGet the String to be converted.Create an empty character array with the length of the String.The charAt() method of the String class returns the character at a particular position. Using this method copy each character of the String to the array.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class StringToCharArray {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter a String value: ");     ... Read More

MySQL Query to Perform Selection Using AND/OR

AmitDiwan
Updated on 09-Oct-2019 12:45:57

110 Views

Let us first create a table −mysql> create table DemoTable (    StudentId int,    StudentName varchar(20),    StudentSubject varchar(20) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 'Chris', 'MongoDB'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(11, 'David', 'MySQL'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(12, 'Bob', 'Java'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(10, 'Carol', 'MySQL'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values(10, 'Chris', 'MongoDB'); Query ... Read More

MySQL Regex to Match a Pattern Ignoring Characters

AmitDiwan
Updated on 09-Oct-2019 12:42:07

184 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(40) ) ; Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John.Smith'); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Chris.Brown'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Chris.Taylor'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select ... Read More

Group Rows by Numeric Characters in MySQL String Field

AmitDiwan
Updated on 09-Oct-2019 12:39:43

172 Views

Fir this, you can concatenate 0 with string field with the help of + operator. The scenario here is like we need to fetch numeric “9844” from a string field “9844Bob”.Let us first create a table −mysql> create table DemoTable (    StudentId varchar(100) ); Query OK, 0 rows affected (0.92 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('9844Bob'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('6375DavidMiller'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('007'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable ... Read More

Round MySQL Column with Float Values

AmitDiwan
Updated on 09-Oct-2019 12:36:12

533 Views

Let us first create a table −mysql> create table DemoTable (    Value float ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(12.4567); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(124.7884); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(45.64643); Query OK, 1 row affected (0.46 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------+ | Value | +---------+ | 12.4567 | | 124.788 | | 45.6464 | +---------+ ... Read More

Implement MySQL Trigger to Insert Records in Second Table

AmitDiwan
Updated on 09-Oct-2019 12:34:23

226 Views

For this, the syntax is as follows −DELIMITER // create trigger yourTriggerName before insert on yourTableName1    for each row    begin          insert into yourTableName2 values (yourValue1, yourValue2, ...N); end ; // DELIMITER ;Let us first create a table −mysql> create table DemoTable1 (    StudentId int,    StudentName varchar(40) ); Query OK, 0 rows affected (0.69 sec)Here is the query to create second table −mysql> create table DemoTable2(    Id int,    Name varchar(40) ); Query OK, 0 rows affected (0.61 sec)Here is the query for trigger before insert −mysql> DELIMITER // mysql> create trigger ... Read More

MySQL Query to Select Date from 00:00 to Today's Date

AmitDiwan
Updated on 09-Oct-2019 12:30:58

372 Views

Let’s say the current date is 2019-09-14 8 :50 :10. Now, we want records from 00 :00 to 2019-09-14 8 :50 :10. Let us now see an example and create a table −mysql> create table DemoTable (    DueDate datetime ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-09-14'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-09-14 8 :00 :10'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-09-14 8 :44 :00'); Query OK, 1 row affected (0.14 sec) mysql> insert ... Read More

Exclude Some ID Records from a List in MySQL

AmitDiwan
Updated on 09-Oct-2019 12:22:59

800 Views

To exclude records, use MySQL NOT IN(). Let us first create a table −mysql> create table DemoTable (    Id int ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(2); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(3); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(4); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable values(5); Query OK, 1 row affected (0.09 sec) mysql> insert into ... Read More

Update Specific Records in a Range with a Single MySQL Query

AmitDiwan
Updated on 09-Oct-2019 12:20:01

190 Views

Let us first create a table −mysql> create table DemoTable (    Name varchar(40),    Position int ); Query OK, 0 rows affected (1.17 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 90); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('David', 67); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob', 55); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Sam', 40); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More

Advertisements