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);
    }

}
Oldwax
  • 1
  • 1
  • Welcome to SO, please keep in mind always seearch before ask new question, for the answer please see here. https://stackoverflow.com/a/13904139/15758781 – Lunatic Mar 03 '22 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? – Oldwax Mar 03 '22 at 21:41
  • Please [reconsider your use of JDBC on Android](https://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android). – CommonsWare Mar 03 '22 at 21:47
  • That's not what i had in mind but it really looks way better, i'll give it a try. Thamks! – Oldwax Mar 04 '22 at 12:28

0 Answers0