0

I am trying to connect to my Redshift database from my android app using the JDBC driver(JDBC42 driver) provided by AWS. In the process of connecting, I am getting "java.lang.ClassNotFoundException: Didn't find class "java.sql.DriverAction" on path: DexPathList".

Details of the JAR files included are:

  1. implementation files('libs/aws-java-sdk-core-1.11.118.jar')
  2. implementation files('libs/aws-java-sdk-redshift-1.11.118.jar')
  3. implementation files('libs/aws-java-sdk-sts-1.11.118.jar')
  4. implementation files('libs/commons-codec-1.9.jar')
  5. implementation files('libs/commons-logging-1.1.3.jar')
  6. implementation files('libs/httpclient-4.5.2.jar')
  7. implementation files('libs/httpcore-4.4.4.jar')
  8. implementation files('libs/jackson-annotations-2.10.1.jar')
  9. implementation files('libs/jackson-core-2.10.1.jar')
  10. implementation files('libs/jackson-databind-2.10.1.jar')
  11. implementation files('libs/jackson-dataformat-cbor-2.10.1.jar')
  12. implementation files('libs/joda-time-2.8.1.jar')
  13. implementation files('libs/log4j-1.2.17.jar')
  14. implementation files('libs/RedshiftJDBC42-no-awssdk-1.2.45.1069.jar')

In the build.gradle file I have had to include the following as I was facing Java Resource merge issues:

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

The Java compile version is:

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

Below is my Java Code to make the connection:

        Properties props = new Properties();
        props.setProperty("user", "admin");
        props.setProperty("password", "08021994Feb");
        try{
            Class.forName("com.amazon.redshift.jdbc42.Driver");
            Connection con = DriverManager.getConnection(URL, props);
           }

I have been successful in connecting to Redshift database using the above mentioned URL and username password via SQL Workbench but the same is not working out here. I have tried with a bunch of different versions of the JAR files but nothing has worked out. Am I missing something here?

harry23
  • 11
  • 2
  • 1
    FYI: [JDBC vs Web Service for Android](https://stackoverflow.com/q/15853367/295004) – Morrison Chang Mar 09 '22 at 01:16
  • Actually, it's an application for a college project which I just need to get up and running to run very basic SQL queries on Redshift hence, going the Web Service way seems to me as an overkill. – harry23 Mar 09 '22 at 03:38
  • 1
    Redshift is a Amazon product for big data. I'm sure Amazon would have you use AWS Amplify or build your own REST solution. All of the packages you listed may not be supported on Android as Android !=Java SE nor Linux. – Morrison Chang Mar 09 '22 at 05:43
  • Recent versions of JDBC drivers are likely not to work on Android as they probably use features and classes (like `java.sql.DriverAction` in your case) that are not available on Android. – Mark Rotteveel Mar 09 '22 at 10:55
  • @MorrisonChang and Mark. Thanks for your replies. Are there any easy to implement alternative libraries(or any other off-the-shelf products) that would let me connect my android app to Redshift. (Other than building my own REST solution) – harry23 Mar 09 '22 at 18:40

0 Answers0