WE PROVIDE ALL

Capitals Of All Countries


          

I Here by given all the country capitals are given and recently modified(or) changed capitals are also mentioned here. All the Capitals of the countries in the world are given below in Alphabetical Order  from A to Z. 

                Country        Capital city
  1. A

    • Afghanistan -> Kabul
    • Albania -> Tirana
    • Algeria  -> Algiers
    • Andorra ->Andorra la Vella
    • Angola ->Luanda
    • Antigua and Barbuda-> Saint John's
    • Argentina-> Buenos Aires
    • Armenia ->Yerevan
    • Australia-> Canberra
    • Austria ->Vienna
    • Azerbaijan->Baku
  • B
    • Bahamas-> Nassau
    • Bahrain-> Manama
    • Bangladesh -> Dhaka
    • Barbados -> Bridgetown
    • Belarus ->Minsk
    • Belgium ->Brussels
    • Belize ->Belmopan
    • Benin ->Porto-Novo
    • Bhutan ->Thimphu
    • Bolivia ->La Paz (administrative); Sucre (judicial)
    • Bosnia and Herzegovina-> Sarajevo
    • Botswana-> Gaborone
    • Brazil ->Brasilia
    • Brunei-> Bandar Seri Begawan
    • Bulgaria-> Sofia
    • Burkina Faso-> Ouagadougou
    • Burundi ->Bujumbura
  • C
    • Cabo Verde ->Praia
    • Cambodia-> Phnom Penh
    • Cameroon-> Yaoundé
    • Canada-> Ottawa
    • Central African Republic-> Bangui
    • Chad-> N'Djamena
    • Chile-> Santiago
    • China ->Beijing
    • Colombia-> Bogotá
    • Comoros ->Moroni
    • Congo, Republic of the-> Brazzaville
    • Congo, Democratic Republic of the-> Kinshasa
    • Costa Rica-> San Jose
    • Cote d'Ivoire ->Yamoussoukro
    • Croatia ->Zagreb
    • Cuba-> Havana
    • Cyprus-> Nicosia
    • Czech Republic-> Prague
  • D
    • Denmark-> Copenhagen
    • Djibouti-> Djibouti (city)
    • Dominica-> Roseau
    • Dominican Republic-> Santo Domingo
  • E
    • Ecuador-> Quito
    • Egypt-> Cairo
    • El Salvador-> San Salvador
    • Equatorial Guinea-> Malabo
    • Eritrea-> Asmara
    • Estonia-> Tallinn
    • Ethiopia-> Addis Ababa
  • F
    • Fiji-> Suva
    • Finland-> Helsinki
    • France-> Paris
  • G
    • Gabon-> Libreville
    • Gambia-> Banjul
    • Georgia-> Tbilisi
    • Germany-> Berlin
    • Ghana-> Accra
    • Greece-> Athens
    • Grenada ->St. George's
    • Guatemala-> Guatemala City
    • Guinea-> Conakry
    • Guinea-Bissau-> Bissau
    • Guyana-> Georgetown
  • H
    • Haiti-> Port-au-Prince
    • Honduras-> Tegucigalpa
    • Hungary-> Budapest
  • I
    • Iceland-> Reykjavik
    • India-> New Delhi
    • Indonesia-> Jakarta
    • Iran-> Tehran
    • Iraq-> Baghdad
    • Ireland-> Dublin
    • Israel-> Jerusalem
    • Italy-> Rome
  • J
    • Jamaica-> Kingston
    • Japan-> Tokyo
    • Jordan-> Amman
  • K
    • Kazakhstan-> Astana
    • Kenya-> Nairobi
    • Kiribati-> South Tarawa
    • Kosovo-> Pristina
    • Kuwait-> Kuwait City
    • Kyrgyzstan-> Bishkek
  • L
    • Laos-> Vientiane
    • Latvia-> Riga
    • Lebanon-> Beirut
    • Lesotho-> Maseru
    • Liberia ->Monrovia
    • Libya-> Tripoli
    • Liechtenstein-> Vaduz
    • Lithuania-> Vilnius
    • Luxembourg-> Luxembourg

  • M
    • Macedonia-> Skopje
    • Madagascar-> Antananarivo
    • Malawi-> Lilongwe
    • Malaysia-> Kuala Lumpur
    • Maldives-> Male
    • Mali-> Bamako
    • Malta-> Valletta
    • Marshall Islands-> Majuro
    • Mauritania-> Nouakchott
    • Mauritius-> Port Louis
    • Mexico-> Mexico City
    • Micronesia-> Palikir
    • Moldova-> Chisinau
    • Monaco-> Monaco
    • Mongolia-> Ulaanbaatar
    • Montenegro-> Podgorica
    • Morocco-> Rabat
    • Mozambique-> Maputo
    • Myanmar (Burma)-> Naypyidaw
  • N
    • Namibia-> Windhoek
    • Nauru-> Yaren District
    • Nepal-> Kathmandu
    • Netherlands-> Amsterdam
    • New Zealand-> Wellington
    • Nicaragua-> Managua
    • Niger-> Niamey
    • Nigeria-> Abuja
    • North Korea-> Pyongyang
    • Norway-> Oslo
  • O
    • Oman-> Muscat
  • P
    • Pakistan-> Islamabad
    • Palau-> Ngerulmud
    • Palestine-> Ramallah
    • Panama-> Panama City
    • Papua New Guinea-> Port Moresby
    • Paraguay-> Asunción
    • Peru-> Lima
    • Philippines-> Manila
    • Poland-> Warsaw
    • Portugal-> Lisbon
  • Q
    • Qatar-> Doha
  • R
    • Romania-> Bucharest
    • Russia-> Moscow
    • Rwanda-> Kigali
  • S
    • Saint Kitts and Nevis-> Basseterre
    • Saint Lucia-> Castries
    • Saint Vincent and the Grenadines-> Kingstown
    • Samoa-> Apia
    • San Marino-> San Marino
    • Sao Tome and Principe-> São Tomé
    • Saudi Arabia-> Riyadh
    • Senegal-> Dakar
    • Serbia-> Belgrade
    • Seychelles-> Victoria
    • Sierra Leone-> Freetown
    • Singapore-> Singapore
    • Slovakia-> Bratislava
    • Slovenia-> Ljubljana
    • Solomon Islands-> Honiara
    • Somalia ->Mogadishu
    • South Africa-> Pretoria (administrative); Cape Town (legislative); Bloemfontein (judicial)
    • South Korea-> Seoul
    • South Sudan-> Juba
    • Spain-> Madrid
    • Sri Lanka-> Sri Jayawardenepura Kotte
    • Sudan-> Khartoum
    • Suriname-> Paramaribo
    • Swaziland-> Mbabane
    • Sweden-> Stockholm
    • Switzerland-> Bern
    • Syria-> Damascus
  • T
    • Taiwan-> Taipei
    • Tajikistan-> Dushanbe
    • Tanzania-> Dodoma
    • Thailand-> Bangkok
    • Timor-Leste-> Dili
    • Togo-> Lomé
    • Tonga-> Nukuʻalofa
    • Trinidad and Tobago-> Port of Spain
    • Tunisia-> Tunis
    • Turkey-> Ankara
    • Turkmenistan-> Ashgabat
    • Tuvalu-> Funafuti
  • U
    • Uganda-> Kampala
    • Ukraine-> Kyiv
    • United Arab Emirates-> Abu Dhabi
    • United Kingdom-> London
    • United States of America-> Washington, D.C.
    • Uruguay-> Montevideo
    • Uzbekistan-> Tashkent
  • V
    • Vanuatu ->Port Vila
    • Vatican City (Holy See)-> Vatican City
    • Venezuela-> Caracas
    • Vietnam-> Hanoi
  • Y
    • Yemen-> Sana'a
  • Z
    • Zambia-> Lusaka
  • Zimbabwe-> Harare

To Reverse a given Number in Java

TO Reverse a Given Number in Java


Steps to do Program:
  1. we take an Integer to store  the given number.
  2. After we have to take a try & catch block. If try block  consists a  error occuring  statement  is in this block.
  3. Then that statement must be  catched by catch block and print the  error occurred because of try & catch block.
  4. According to that While loop it is repeatedly revolving around the loop  until the condition is false (or) not true.
  5. In this While loop  
           5.1  we have taken an variable  temp = n % 10; it stores the remainder in temp.
      
          5.2   Next we have to store the temp variable in to another variable because we have to number                   is  we are getting from that  temp variable.

          5.3 Every  repetation of loop execution temp stores the remainder variable then                                           sum = sum * 10 + temp;  it tells about the every temp variable is stored in  sum. 
            
          5.4  The sum variable is multiplied by 10 because every remainder must be multiplied and                           added the variable to sum.(temp storing the remainder ).
         
           5.5  At the same time we have to reduce the  given number by writing the statement  n=n/10;
                    that statement stores the Quotient  so it reduces the number by  again intialize  that "n"                       in to "n"  by itself. 




public class ReverseNum {
public static void main(String[] args) {
System.out.println("Enter a Number");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m;
m = n;
int sum = 0;
try {
while (n > 0) {
int temp = n % 10;
sum = sum * 10 + temp;
n = n / 10;

}
System.out.println("The number is" + sum);
            if(sum==m)
            {
            System.out.println("The Number is polindrome");
            }
            else
            {
            System.out.println("It is not a polindeome");
            }
} catch (Exception e) {
e.printStackTrace();
}
}
}

Retrieve the data from the Database and Sort the Data Based on Job corresponding to Salary using Collections


Retrieve the data from the Database and Sort the Data Based on Job corresponding to Salary using Collections 


Using this program we can get the entire row by giving any attribute value of that row by using only one Single HashMap and JavaBean. In  this program we used the JDBC connection  to the Database MySQL. we can alter the database table values using Collections.


package com.nt.show;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

class Justify {

public static ArrayList<Employ> all = new ArrayList<Employ>();

public static void add(Employ z) {
all.add(z);

}

public static void display() {
Collections.sort(all, new Comparator<Employ>() {

@Override
public int compare(Employ o1, Employ o2) {
return o1.getJob().compareTo(o2.getJob());
}

});

for (Employ emd : all) {
System.out.println(emd);
}

}

public static void mySort(final String s) {

Collections.sort(all, new Comparator<Employ>() {
@Override
public int compare(Employ o1, Employ o2) {

if (o1.getSalary() > o2.getSalary()&&(o1.getJob().trim().equals(s)))
return 1;
else
return -1;
                     
}
});
System.out.println(" also Started");
for (Employ ex : all) {

System.out.println(ex);

}
}



}

public class Hazard  {

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3307/organization";

// Database credentials
static final String USER = "root";
static final String PASS = "root";

public static void main(String[] args) throws SQLException,
ClassNotFoundException, IOException {
Connection conn = null;
Statement stmt = null;

try {
// STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

// STEP 3: Open a connection
System.out.println("Connecting to database");
conn = DriverManager.getConnection(DB_URL, USER, PASS);

// STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "select id,job,salary from employ;";

ArrayList<Employ> al = new ArrayList<Employ>();
ArrayList<Employ> all = new ArrayList<Employ>();
ResultSet rs = stmt.executeQuery(sql);
Justify zx = new Justify();
Employ z = null;
while (rs.next()) {
z = new Employ();
int empid = (rs.getInt("id"));
String empjob = (rs.getString("Job"));
int salary = rs.getInt("salary");
z.setId(empid);
z.setJob(empjob);
z.setSalary(salary);
al.add(z);

Justify.add(z);

System.out.println(z);

}
System.out.println("Sorting");
long lStartTime = System.currentTimeMillis();
Justify.display();
String y="Tester";
String x="Developer";
Justify.mySort(x);
Justify.mySort(y);

long lEndTime = System.currentTimeMillis();
long difference = lEndTime - lStartTime;

System.out.println("Elapsed milliseconds: " + difference);

}

catch (Exception e) {
e.printStackTrace();
} finally {
stmt.close();
conn.close();
}

}



}
Using the Java Bean we can get the entire user defined set of attributes(datatypes) under single object.

  1. A Java Bean Must have Setter and Getter Methods
  2. It must be implemented by serializable.
  3. It must have a Constructor.

package com.nt.show;

public class Employ {
private int id;
private String job;
private int salary;
Employ(){
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Employ [id=" + id + ", job=" + job + ", salary=" + salary + "]";
}

}

Using Single HashMap we can Retrieve the Entire Row from Database using any Column value

Using Single HashMap we can Retrieve the Entire Row from Database using any Column value

Using this program we can get the entire row by giving any attribute value of that row by using only one Single HashMap and JavaBean. In  this program we used the JDBC connection  to the Database MySQL. we can alter the database table values using Collections.


package morning;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Scanner;


public class Until {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3307/organization";

// Database credentials
static final String USER = "root";
static final String PASS = "root";

public static void main(String[] args) throws SQLException,
ClassNotFoundException, IOException {
Connection conn = null;
Statement stmt = null;

try {
// STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

// STEP 3: Open a connection
System.out.println("Connecting to database");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
            Scanner sc =new Scanner(System.in);
         
// STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "select id,job,salary from employ;";
ResultSet rs = stmt.executeQuery(sql);

while (rs.next()) {
Employ z = new Employ();
int empid = (rs.getInt("id"));
String empjob = (rs.getString("Job"));
int salary = rs.getInt("salary");
z.setId(empid);
z.setJob(empjob);
z.setSalary(salary);
SearchEmp.add(z);
}
String key;
System.out.println("Enter the name you want to search ");
System.out.println("Enter 1. EmpId    2.Salary      3.Job");
int x=sc.nextInt();
switch(x)
{
case 1:
   System.out.println("Enter the EmpId");
      key=sc.next();
        SearchEmp.display(x,key);
        break;
     
case 2:   System.out.println("Enter the Salary ");
         key=sc.next();
                   SearchEmp.display(x,key);
                    break;
                 
case 3:       System.out.println("Enter Job");
         key=sc.next();
        SearchEmp.display(x,key);
        break;
}
}
catch(Exception e)
{
e.printStackTrace();
}

}
}

Using the JavaBean we can get the entire user defined set of attributes(datatypes) under single object.

  1. A JavaBean Must have Setter and Getter Methods
  2. It must be implemented by serializable.
  3. It must have a Constructor.


package morning;

public class Employ {
private int id;
private String job;
private int salary;
Employ(){
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Employ [id=" + id + ", job=" + job + ", salary=" + salary + "]";
}

}

How to sort the Database Table (ordered by Job) using Collections

In this Program we are sorting based on their Job Category and Based on their Salary also. In this we taken Java Bean as object to sort the database table.We used Comparator for sorting and Employee type objects are stored in ArrayLists for Sorting.

package com.nt.finals;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

class Justify {

public static ArrayList<Employ> ald = new ArrayList<Employ>();
public static ArrayList<Employ> alt = new ArrayList<Employ>();

public static void add(Employ z) {

// TODO Auto-generated method stub
alt.add(z);}


public static void add1(Employ z) {
ald.add(z);

}
public static void display()
{
Collections.sort(ald, new Comparator<Employ>() {

@Override
public int compare(Employ o1, Employ o2) {
// TODO Auto-generated method stub
if(o1.getSalary()>o2.getSalary())
return 1;
else
return -1;
}

});

for (Employ emd : ald) {

System.out.println(emd);
}
Collections.sort(alt, new Comparator<Employ>() {

@Override
public int compare(Employ o1, Employ o2) {
// TODO Auto-generated method stub
if(o1.getSalary()>o2.getSalary())
return 1;
else
return -1;
}

});

for (Employ em : alt) {

System.out.println(em);
}



}
}

public class Hazard {

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3307/organization";

// Database credentials
static final String USER = "root";
static final String PASS = "root";

public static void main(String[] args) throws SQLException,
ClassNotFoundException, IOException {
Connection conn = null;
Statement stmt = null;

try {
// STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

// STEP 3: Open a connection
System.out.println("Connecting to database");
conn = DriverManager.getConnection(DB_URL, USER, PASS);

// STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "select id,job,salary from employ;";

ArrayList<Employ>ald=null;
ArrayList<Employ>alt=null;
ArrayList<Employ> al = new ArrayList<Employ>();
ResultSet rs = stmt.executeQuery(sql);
Justify zx = new Justify();

while (rs.next()) {
Employ z = new Employ();
int empid = (rs.getInt("id"));
String empjob = (rs.getString("Job"));
int salary = rs.getInt("salary");
z.setId(empid);
z.setJob(empjob);
z.setSalary(salary);
al.add(z);
String strs = "Tester";
String x = "Developer";
if (empjob.trim().equals(x)) {
zx.add1(z);
}

else if (empjob.trim().equals(strs)) {
zx.add(z);

}

System.out.println(z);

}
System.out.println("Sorting");
Justify.display();


}

catch (Exception e) {
e.printStackTrace();
} finally {
stmt.close();
conn.close();
}

}
}


package com.nt.finals;

public class Employ {
private int id;
private String job;
private int salary;
Employ(){

}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Employ [id=" + id + ", job=" + job + ", salary=" + salary + "]";
}

}


How to sort Database table(Many columns) using Comparable in collections

How to sort Database table(Many columns) using Comparable in collections:

we can sort the Database Table of multiple columns using the Comparable in the  Collection  concept.
package com.nt.extensive;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class User {

public static void main(String[] args) throws IOException {

final String DB_URL = "jdbc:mysql://localhost:3307/organization";
    Scanner sc=new Scanner(System.in);
// Database credentials
final String USER = "root";
final String PASS = "root";

Connection conn = null;
Statement stmt = null;
try {
// STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

// STEP 3: Open a connection
System.out.println("Connecting to database");
conn = DriverManager.getConnection(DB_URL, USER, PASS);

if (conn != null)
// STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = null;
if (stmt != null)

sql = "SELECT ename,epassword,phonenumber,email,salary,Age FROM employee";

ResultSet rs = stmt.executeQuery(sql);
if (rs != null)
while (rs.next()) {
String sname = rs.getString("ename");
String password = rs.getString("epassword");
Long phonenumbers = rs.getLong("phonenumber");
String eemail = rs.getString("email");
Double Salary = rs.getDouble("salary");
int Age = rs.getInt("age");
System.out.print(sname);
System.out.print("\t");
System.out.print(Age);
System.out.print("\t");
System.out.print(password);
System.out.print("\t\t");
System.out.print(phonenumbers);
System.out.print("\t\t\t");
System.out.print(eemail);
System.out.print("\t\t\t");
System.out.print(Salary);
System.out.println();
}
ResultSetMetaData rsmd=rs.getMetaData();

int num=rsmd.getColumnCount();
System.out.println(num+" Columns");
for(int i=1;i<=num;i++)
{
System.out.println("Column Names        "+rsmd.getColumnName(i));
}
System.out.println("Enter 1. For Salary \t ");
System.out.println("Enter 2. For Ename \t ");
int i=sc.nextInt();

ResultSet rs1 = stmt.executeQuery("Select * from employee");
ArrayList<Newsort> al = new ArrayList<Newsort>();

while (rs1.next()) {

Newsort e = new Newsort();
String sname = (rs1.getString("ename"));
String password = (rs1.getString("epassword"));
Long phonenum = (rs1.getLong("phonenumber"));
String Email = (rs1.getString("Email"));
Double sal = (rs1.getDouble("salary"));
int age=(rs1.getInt("Age"));

e.setEname(sname);
e.setEpassword(password);
e.setPhonenumber(phonenum);
e.setEmail(Email);
e.setSalary(sal);
e.setAge(age);
                 e.setManipulate(i);
al.add(e);
               
}



for (Newsort em : al) {
System.out.println(em);
}

Collections.sort(al);
System.out.println("Sort Employees based on your Requirement ");


for (Newsort em : al) {
System.out.println(em);
}


}

catch (NullPointerException Ne) {
System.out.println("NullPointerException");
}

catch (ClassNotFoundException e) {
System.out.println("UnRegistered Driver");
} catch (SQLException sw) {
System.out.println("SqlException");
} finally {

try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();

}
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}



}

 Java Bean Class Related to the Creation of NewSort;

In this Newsort Class  we created the object of  lncluding several types of objects under a Single JavaBean Class that is Newsort.

package com.nt.extensive;

public class Newsort implements Comparable<Newsort> {

String Ename;
String Epassword;
int Age;
Double Salary;
Long Phonenumber;
String Email;
int i;

void NewSort(String ename, String epassword, int age, Double salary,
Long phonenumber) {

setEname(ename);
setEpassword(epassword);
setAge(age);
setSalary(salary);
setPhonenumber(phonenumber);
}

public String getEname() {
return Ename;
}

public void setEname(String ename) {
Ename = ename;
}

public String getEpassword() {
return Epassword;
}

public void setEpassword(String epassword) {
Epassword = epassword;
}

public int getAge() {
return Age;
}

public void setAge(int age) {
Age = age;
}

public Double getSalary() {
return Salary;
}

public void setSalary(double salary) {
Salary = salary;
}

public Long getPhonenumber() {
return Phonenumber;
}

public void setPhonenumber(Long phonenumber) {
Phonenumber = phonenumber;
}

public String getEmail() {
return Email;
}

public void setEmail(String email) {
Email = email;
}

public int getManipulate() {
return i;
}

public void setManipulate(int z) {
i = z;
}

@Override
public String toString() {
return "Newsort [Ename=" + Ename + ", Epassword=" + Epassword
+ ", Age=" + Age + ", Salary=" + Salary + ", Phonenumber="
+ Phonenumber + ", Email=" + Email + "]";
}

@Override
public int compareTo(Newsort z) {
int value = 0;
int x = this.getManipulate();
// System.out.println("Enter the number");
if (x == 1) {

{
value = this.Salary.compareTo(z.getSalary());
}

} else if (x == 2) {
{
value = this.Ename.compareTo(z.getEname());
}
}

return value;
}

}

How to Retrive the Database table and Sorting table using Java




package com.nt.sense;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;

public class Restore {

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3307/organization";

// Database credentials
static final String USER = "root";
static final String PASS = "root";

public static void main(String[] args) throws SQLException,
ClassNotFoundException {
Connection conn = null;
Statement stmt = null;
@SuppressWarnings("unused")
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

// STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

// STEP 3: Open a connection
System.out.println("Connecting to database");
conn = DriverManager.getConnection(DB_URL, USER, PASS);

// STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "SELECT ename,epassword,phonenumber,email FROM employee";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
String sname = rs.getString("ename");
String password = rs.getString("epassword");
BigDecimal phonenumbers = rs.getBigDecimal("phonenumber");
String eemail = rs.getString("email");
System.out.print(sname);
System.out.print("\t");
System.out.print(password);
System.out.print("\t");
System.out.print(phonenumbers);
System.out.print("\t");
System.out.print(eemail);
System.out.println();
}
System.out.println("this is the display of ename only");
String sql2;
sql2 = "SELECT epassword from employee";
ResultSet rs1 = stmt.executeQuery(sql2);
System.out.println("start.....");
ArrayList<String> al = new ArrayList<String>();
while (rs1.next()) {
{
al.add(rs1.getString("epassword"));
}

}

for (String s : al) {
System.out.println(s);
}

Collections.sort(al);
System.out.println("After sorting");
for (String s1 : al) {
System.out.println(s1);
}
}

}