简体   繁体   English

无法将 Android Studio 与 Oracle 数据库 19c 连接

[英]Can't connect Android Studio with Oracle Database 19c

I've recently tried to connect Android Studio with an OracleDB through ojdbc driver without success.我最近尝试通过 ojdbc 驱动程序将 Android Studio 与 OracleDB 连接,但没有成功。

I'm using ojdbc8.jar, Oracle Database 19c and jdk1.8.0_241 on Windows10.我在 Windows10 上使用 ojdbc8.jar、Oracle 数据库 19c 和 jdk1.8.0_241。

I tried to do the exact same thing with the same code and components in Intellij and everything went well.我尝试在 Intellij 中使用相同的代码和组件做完全相同的事情,一切顺利。

When I try to connect to the database I received the following error: see_error_print "java.lang.NoClassDefFoundError: Failed resolution of: Ljava/sql/DriverAction;"当我尝试连接到数据库时,我收到以下错误: see_error_print "java.lang.NoClassDefFoundError: Failed resolution of: Ljava/sql/DriverAction;" in the line Class.forName.在 Class.forName 行中。

I have installed Android 28 and my gradle version is 3.6.2.. I tried to clean project, and invalidate caches/restart, but nothing seems to work.我已经安装了 Android 28 并且我的 gradle 版本是 3.6.2 .. 我试图清理项目,并使缓存/重新启动无效,但似乎没有任何效果。

In fact, in Android28 (Sdk) at java.sql, indeed the missing file isn't there, but exists in jdk.事实上,在 java.sql 的 Android28 (Sdk) 中,确实不存在丢失的文件,但存在于 jdk 中。

I appreciate any help I can get, thank you.我很感激我能得到的任何帮助,谢谢。 PS:, english is not my mother language. PS:,英语不是我的母语。 sorry if there are any mistakes.抱歉,如果有任何错误。

Here is the code I used:这是我使用的代码:

package com.lamtias.isplit.ActivityLogin;

import android.os.Bundle;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import com.lamtias.isplit.Logic.ISplit;
import com.lamtias.isplit.R;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class SignUpActivity extends AppCompatActivity {

    private ISplit iSplit;
    private static final String DEFAULT_DRIVER = "oracle.jdbc.driver.OracleDriver";
    private static final String DEFAULT_URL = "jdbc:oracle:thin:@localhost:1521:ISplitDB";
    private static final String DEFAULT_USERNAME = "c##marcia";
    private static final String DEFAULT_PASSWORD = "marcia";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        JDBCexample(DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
    }

    public static void JDBCexample(String dbid, String userid, String passwd)
    {
        try {

            Class.forName ("oracle.jdbc.driver.OracleDriver");
            Connection conn = DriverManager.getConnection(
                    "jdbc:oracle:thin:@localhost:1521:ISplitDB", userid, passwd);
            if(conn!=null)
                System.out.println ("oiiiiiiiiiiiiiiiiiiiiiiiiiiii");
            else
                System.out.println ("oeeeeeeeeeeeeeeeeeeeeeeeeeeee");
            Statement stmt = conn.createStatement();
            //stmt.executeUpdate( "insert into users values ('1', 'Perryridge')");
            stmt.close();
            conn.close();
        }
        catch (SQLException sqle) {
            System.out.println("SQLException : " + sqle);
        } catch (Exception e){
            System.out.println("Exception : " + e);
        }
    }
}

I have fixed the same problem using ojdbc8.jar from Oracle OJDBC 18.3: https://www.oracle.com/database/technologies/appdev/jdbc-ucp-183-downloads.html I have fixed the same problem using ojdbc8.jar from Oracle OJDBC 18.3: https://www.oracle.com/database/technologies/appdev/jdbc-ucp-183-downloads.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM