first you have to create connection to your database, You can use JDBC for it.
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
public Dbconnection()
{
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/databasename","root","root");
}
catch(Exception e)
{
System.out.println("Error in connection"+e);
}
}
connection created in the constructor,
method to get all rows from a table
public void getData()
{
try{
ps=con.prepareStatement("select * from tbl_name");
rs=ps.executeQuery();
while(rs.next())
{
System.out.println(rs.getString(1)); //here you can get data, the '1' indicates column number based on your query
}
}
catch(Exception e)
{
System.out.println("Error in getData"+e);
}
}
In the while loop you can all data from rs using rs.getString(1)
NB: change column number for different column.
To get more idea please refer the links:
http://www.tutorialspoint.com/jdbc/index.htm
http://www.w3schools.com/sql/
SELECT * FROM db_name.table_name