Sort Character Values from a Column Mixed with Characters and Numbers in MySQL

AmitDiwan
Updated on 26-Feb-2020 05:19:51

218 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Code varchar(20)    -> ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('J23'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('C13'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('A61'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('D56'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following ... Read More

String Concatenation in Java

Ayyan
Updated on 26-Feb-2020 05:16:46

659 Views

You can concatenate two strings in Java either by using the concat() method or by using the ‘+’ , the “concatenation” operator.The concat() methodThe concat() method appends one String to the end of another. This method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.Examplepublic class ConncatSample {    public static void main(String []args) {       String s1 = "Hello";       String s2 = "world";       String res = s1.concat(s2);       System.out.print("Concatenation result:: ");     ... Read More

Concatenation of Strings in Java

Alankritha Ammu
Updated on 26-Feb-2020 05:14:28

197 Views

You can finish your task by combining/ concatenating your two stings using concat() method or + operator.Exampleimport java.util.Scanner; public class ConncatSample {    public static void main(String []args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter your first name");       String firstName = sc.nextLine();       System.out.println("Enter your last name");       String lastName = sc.nextLine();       String completeName = firstName+lastName;       System.out.print("Hi your complete name is :: ");       System.out.println(completeName);    } }OutputEnter your first name KrishnaKasyap Enter your last name BhagavatulaHi your complete ... Read More

Different Ways to Concatenate Strings in Java

Anjana
Updated on 26-Feb-2020 05:13:14

563 Views

You can concatenate two strings in Java either by using the concat() method or by using the ‘+’ , the “concatenation” operator.Examplepublic class ConncatSample {    public static void main(String []args) {       String s1 = "Hello";       String s2 = "world";       String res1 = s1.concat(s2);       String res2 = s1+s2;       System.out.print("Concatenation using method:: ");       System.out.println(res1);       System.out.print("Concatenation using operator:: ");       System.out.println(res2);    } }OutputConcatenation using method:: Helloworld Concatenation using operator:: Helloworld

Manipulating Strings in Java

Manikanth Mani
Updated on 26-Feb-2020 05:12:20

668 Views

Since String class is immutable once created we cannot modify the data of the string. But still if you want to manipulate string data you can rely on StringBuffer or StringBuilder classes.Examplepublic class Test {    public static void main(String args[]) {       String str = "Hi welcome ";       StringBuffer sb= new StringBuffer(str);       sb.append("to Tutorialspoint");       System.out.println(sb);    } }OutputHi welcome to Tutorialspoint

Ways to Manipulate Strings in Java

Ayyan
Updated on 26-Feb-2020 05:11:31

172 Views

Since String class is immutable once created we cannot modify the data of the string. But still, if you want to manipulate string data you can rely on StringBuffer or StringBuilder classes.Examplepublic class Test {    public static void main(String args[]) {       String str = "Hi welcome ";       StringBuffer sb= new StringBuffer(str);       sb.append("to Tutorialspoint");       System.out.println(sb);    } }OutputHi welcome to Tutorialspoint

Reverse a Given String While Preserving Space Position in Java

Akshaya Akki
Updated on 26-Feb-2020 05:09:40

5K+ Views

You can reverse the contents of a given String using leaving the spaces using the reverse() method of the StringBuffer class.Examplepublic class Test {    public static void main(String args[]) {       String str = "hi welcome to Tutorialspoint";       String strArray[] = str.split(" ");       StringBuffer sb= new StringBuffer(str);       sb.reverse();       for(int i=0 ; i

Remove Last Character from a String in Java

Alankritha Ammu
Updated on 26-Feb-2020 05:07:49

2K+ Views

The StringBuffer class contains a method known as deleteCharAt(). This method deletes the character at a specified index/position. You can use this method to delete/remove a particular character from a string in Java.Examplepublic class Test {    public static void main(String args[]){       String str = "hi welcome to Tutorialspoint";       StringBuffer sb= new StringBuffer(str);       sb.deleteCharAt(sb.length()-1);       System.out.println(sb);    } }Outputhi welcome to Tutorialspoint

Fetch Single Result from a Table in Java MySQL

AmitDiwan
Updated on 26-Feb-2020 05:04:00

3K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (1.37 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(101, 'Chris'); Query OK, 1 row affected (0.54 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(103, 'Mike'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output −+------+-------+ | Id   ... Read More

Insert Single Column into MySQL Table with Java

AmitDiwan
Updated on 26-Feb-2020 05:03:06

584 Views

Use INSERT INTO statement in the Java-MySQL connection code to insert a column.Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.54 sec)Here is the Java code to insert only a single column into a MySQL table.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class InsertOneColumnDemo {    public static void main(String[] args) {       Connection con = null;       PreparedStatement ps = null;       try {          con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web?" + "useSSL=false", "root", "123456");   ... Read More

Advertisements