The Boolean class of the lang package provides two method namely parseBoolean() and valueOf().parseBoolean(String s) − This method accepts a String variable and returns boolean. If the given string value is "true" (irrespective of its case) this method returns true else, if it is null or, false or, any other value it returns false.valueOf(String s) − This method accepts a String value, parses it and returns an object of the Boolean class based on the given value. You can use this method instead of the constructor. If the given String value is "true" this method returns true or, it returns ... Read More
Using the Runtime classJava provides a class named java.lang.Runtime, using this class you can interface with the current environment.The getRunTime() (static) method of this class returns a Runtime object associated with the current application.The exec() method accepts a String value representing the command to execute a process in the current environment (system) and executes it.Therefore, to execute an external application using the Runtime class −Get the run time object using the getRuntime() method.Execute the required process by passing the path of it as a String value to the exec() method.Exampleimport java.io.IOException; public class Trail { public static void main(String ... Read More
The URL class of the java.net package represents a Uniform Resource Locator which is used to point a resource (file or, directory or a reference) in the world wide web.The openStream() method of this class opens a connection to the URL represented by the current object and returns an InputStream object using which you can read data from the URL.Therefore, to read data from web page (using the URL class) −Instantiate the java.net.URL class by passing the URL of the desired web page as a parameter to its constructor.Invoke the openStream() method and retrieve the InputStream object.Instantiate the Scanner class ... Read More
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName, LastName) values('John', 'Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(FirstName, LastName) values('David', 'Miller'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(FirstName, LastName) values('John', 'Doe'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(FirstName, LastName) values('Chris', 'Brown'); Query OK, 1 row affected (0.15 sec)Display all records from ... Read More
Let us first create a table −mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected ... Read More
Since we want the sum of last 3 digits, we need to use aggregate function SUM() along with RIGHT(). Let us first create a table −mysql> create table DemoTable ( Code int ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(5464322); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(90884); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(23455644); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(4353633); Query OK, 1 row affected (0.11 sec)Display all records from ... Read More
Here, let’s say you have a string with form “StringSeparatorNumber” form like John/56989. Now if you want to remove the number after separator /, then use the SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable ( StudentName varchar(100) ); Query OK, 0 rows affected (1.05 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John/56989'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('David/74674'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Bob/45565'); Query ... Read More
For thus, use MySQL REPLACE(). Let us first create a table −mysql> create table DemoTable ( FolderLocation text ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('C/ProgramFiles/AllMySQLProgram'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('C/ProgramFiles/JavaChatApplication'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('C/ProgramFiles/Main/Image.png'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------------------------------------+ | FolderLocation ... Read More
Yes, we can check for a blank string and 0 in a single condition. Let us first create a table −mysql> create table DemoTable ( ClientId varchar(40) ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('CLI-01'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values('0'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-02'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable values('CLI-00'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(''); Query OK, 1 ... Read More
To collapse rows into a comma-delimited list, use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable ( Id int, Name varchar(40) ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris Brown'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(101, 'Adam Smith'); Query OK, 1 row affected (0.84 sec) mysql> insert into DemoTable values(101, 'John Doe'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(100, 'David Miller'); Query OK, 1 row affected (0.17 sec) mysql> insert ... Read More