Step 1:

Gather oracle thin driver detail ie., driver class name, URL and etc
Check the sid in sql plus of yours ie.,

 
In the above the adm is the sid name

Step 2:

Write java application as shown below using oracle thin driver
import java.sql.*;
public class thin
{
            public static void main(String[] args)
            {
                        try
                        {

                        Class.forName("oracle.jdbc.driver.OracleDriver");
                        System.out.println("Driver Loaded");
                        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:adm","scott","tiger");
                        if(con==null)
                System.out.println("Connection not established");
                        else
                System.out.println("Connection  established");
                        Statement st=con.createStatement();
                        System.out.println("statement obj is created");
                        ResultSet rs=st.executeQuery("Select * from dept");
                        System.out.println("query excuted and resultset obj is generated");

                        ResultSetMetaData rsmd=rs.getMetaData();
                        for(int i=1;i<=rsmd.getColumnCount();++i)
                                    System.out.print(rsmd.getColumnLabel(i)+"  ");

                        System.out.println("\n\n");



                        while(rs.next())
                        {
                                    System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getString(3));

                        }
                        System.out.println("result set is proccessed");

                        rs.close();
                        st.close();
                        con.close();
                        }//try
                        catch(SQLException se)
                        {
                                    se.printStackTrace();
                        }
                        catch(ClassNotFoundException cnf)
                        {
                                    cnf.printStackTrace();
                        }
                       
/*catch(IOException ioe)
                        {
                                    ioe.printStackTrace();
                        }
*/
catch(Exception e)
                        {
                                    e.printStackTrace();
                        }


            }
}
Step 3
Set the classpath properly the check the out put in command prompt