Have you registered the driver?
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Try Following these steps (Check if you missed anything):
1) Import the following packages in your java file:***********
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
2) Load and Register the JDBC driver:***********
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
or you can use
Class.forName("oracle.jdbc.driver.OracleDriver");
3) Connect to database:***********
a) If you are using oracle oci driver,you have to use:
Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@oracle.world", "root", "root");
where oracle.world is the TNSNAMES entry and root is the username and password.
b) If you are using oracle thin driver,you have to use:
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:mydatabase","root", "root");
where localhost is the host,3306 is the port, mydatabase is the database and root is the username and password.
4) Querying the database:**********
a)create statement:
Statement st = conn.createStatement();
b)write query and execute the query:
ResultSet rs = st.executeQuery("SELECT * from student");
5) Close the statement,resultset and connection:**********
rs.close();
st.close();
conn.close();