0

I'm pretty new to java and specially to android and i got stuck making a little project on my own so i'd be very glad someone could help me.

I'm trying to make my app connect to a free tier oracle database (19c) and despite having set the ojdbc8.jar driver inside app/libs I keep getting java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver.

I also searched several threads and none of the solutions has worked for me.

I don't want to purchase oracle mobile connector given that is just a test app to learn.

Here's my code.

import java.sql.*;

public class ConnectionToOracleDB {

    private static final String DEFAULT_DRIVER = "oracle.jdbc.driver.OracleDriver";
    private static final String DEFAULT_URL = "jdbc:oracle:thin:@dbmc_high...?TNSADMIN=(tnsnames location)";
    private static final String DEFAULT_USERNAME = "USER";
    private static final String DEFAULT_PASSWORD = "PASSWORD";

    private Connection connection;

    public void main() {
        try {
            this.connection = createConnection();
            Statement stmt=connection.createStatement();
            StringBuffer stringBuffer = new StringBuffer();
            ResultSet rs=stmt.executeQuery("select 1 from DUAL");
            while(rs.next()) {
                stringBuffer.append( rs.getString(1)+"\n");
            }
            System.out.println(stringBuffer.toString());
            connection.close();
        }
        catch (Exception e) {

            System.out.println(e);
        }
    }

    public static Connection createConnection(String driver, String url, String username, String password) throws ClassNotFoundException, SQLException {

        Class.forName(driver);
        return DriverManager.getConnection(url, username, password);
    }

}
4
  • Welcome to SO, please keep in mind always seearch before ask new question, for the answer please see here. stackoverflow.com/a/13904139/15758781 Commented Mar 3, 2022 at 20:21
  • Hi, that one was the first i tried and sadly didn't fix the problem. Any idea of what else could be? Commented Mar 3, 2022 at 21:41
  • Please reconsider your use of JDBC on Android. Commented Mar 3, 2022 at 21:47
  • That's not what i had in mind but it really looks way better, i'll give it a try. Thamks! Commented Mar 4, 2022 at 12:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.