Android的Oracle数据库JDBC6(Android Oracle Database JDB

2019-08-05 18:50发布

嗨,我想创建我的Oracle数据库的连接。 我以前使用的ojdbc14.jar的,一切工作正常,但连接应该是安全的,我想这些文件进行加密。 所以我决定现在使用ojdbc5.jar。 罐子是即时通讯我的“库”文件夹

从jdbc14改变的原因jdbc6我想用属性为我的DB和我的设备之间的安全数据交换

早些时候,我还试图jdbc5但有了这个,我只得到了一个Java堆大小错误。

public class MainActivity extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        jdbccoonect connect = new jdbccoonect();
        connect.execute();


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    private class jdbccoonect extends AsyncTask<Void, Integer, Boolean>
    {

        @Override
        protected Boolean doInBackground(Void... params)
        {
            // TODO Auto-generated method stub
            String username = "scott";
            String password = "tiger";
            try
            {
                Log.d("HI","HI");
                Class.forName("oracle.jdbc.OracleDriver");
                            //Class.forName("oracle.jdbc.driver.OracleDriver");



                /*Connection conn = DriverManager
                        .getConnection("jdbc:oracle:thin://@10.10.0.9:1521/service",
                                        username, password);*/

                Log.d("HI","HI");
            }
            catch (ClassNotFoundException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

    }

}

错误:

01-05 22:27:56.814: D/HI(1610): HI
01-05 22:27:57.005: E/dalvikvm(1610): Could not find class 'javax.management.MBeanServer', referenced from method oracle.jdbc.driver.OracleDriver.registerMBeans
01-05 22:27:57.005: W/dalvikvm(1610): VFY: unable to resolve check-cast 716 (Ljavax/management/MBeanServer;) in Loracle/jdbc/driver/OracleDriver;
01-05 22:27:57.005: D/dalvikvm(1610): VFY: replacing opcode 0x1f at 0x002d
01-05 22:27:57.005: I/dalvikvm(1610): Could not find method java.lang.management.ManagementFactory.getPlatformMBeanServer, referenced from method oracle.jdbc.driver.OracleDriver.registerMBeans
01-05 22:27:57.005: W/dalvikvm(1610): VFY: unable to resolve static method 3734: Ljava/lang/management/ManagementFactory;.getPlatformMBeanServer ()Ljavax/management/MBeanServer;
01-05 22:27:57.005: D/dalvikvm(1610): VFY: replacing opcode 0x71 at 0x0080
01-05 22:27:57.015: I/dalvikvm(1610): Could not find method java.lang.management.ManagementFactory.getPlatformMBeanServer, referenced from method oracle.jdbc.driver.OracleDriver.registerMBeans
01-05 22:27:57.015: W/dalvikvm(1610): VFY: unable to resolve static method 3734: Ljava/lang/management/ManagementFactory;.getPlatformMBeanServer ()Ljavax/management/MBeanServer;
01-05 22:27:57.015: D/dalvikvm(1610): VFY: replacing opcode 0x71 at 0x0094
01-05 22:27:57.015: I/dalvikvm(1610): Could not find method java.lang.management.ManagementFactory.getPlatformMBeanServer, referenced from method oracle.jdbc.driver.OracleDriver.registerMBeans
01-05 22:27:57.015: W/dalvikvm(1610): VFY: unable to resolve static method 3734: Ljava/lang/management/ManagementFactory;.getPlatformMBeanServer ()Ljavax/management/MBeanServer;
01-05 22:27:57.015: D/dalvikvm(1610): VFY: replacing opcode 0x71 at 0x00a8
01-05 22:27:57.015: I/dalvikvm(1610): Could not find method java.lang.management.ManagementFactory.getPlatformMBeanServer, referenced from method oracle.jdbc.driver.OracleDriver.registerMBeans
01-05 22:27:57.015: W/dalvikvm(1610): VFY: unable to resolve static method 3734: Ljava/lang/management/ManagementFactory;.getPlatformMBeanServer ()Ljavax/management/MBeanServer;
01-05 22:27:57.015: D/dalvikvm(1610): VFY: replacing opcode 0x71 at 0x00bc
01-05 22:27:57.015: I/dalvikvm(1610): Could not find method java.lang.management.ManagementFactory.getPlatformMBeanServer, referenced from method oracle.jdbc.driver.OracleDriver.registerMBeans
01-05 22:27:57.015: W/dalvikvm(1610): VFY: unable to resolve static method 3734: Ljava/lang/management/ManagementFactory;.getPlatformMBeanServer ()Ljavax/management/MBeanServer;
01-05 22:27:57.015: D/dalvikvm(1610): VFY: replacing opcode 0x71 at 0x00d1
01-05 22:27:57.025: W/dalvikvm(1610): VFY: unable to resolve exception class 712 (Ljavax/management/JMException;)
01-05 22:27:57.025: W/dalvikvm(1610): VFY: unable to resolve exception class 712 (Ljavax/management/JMException;)
01-05 22:27:57.025: W/dalvikvm(1610): VFY: unable to resolve exception class 712 (Ljavax/management/JMException;)
01-05 22:27:57.025: W/dalvikvm(1610): VFY: unable to find exception handler at addr 0xfa
01-05 22:27:57.025: W/dalvikvm(1610): VFY: rejected Loracle/jdbc/driver/OracleDriver;.registerMBeans ()V
01-05 22:27:57.025: W/dalvikvm(1610): VFY: rejecting opcode 0x0d at 0x00fa
01-05 22:27:57.025: W/dalvikvm(1610): VFY: rejected Loracle/jdbc/driver/OracleDriver;.registerMBeans ()V
01-05 22:27:57.025: W/dalvikvm(1610): Verifier rejected class Loracle/jdbc/driver/OracleDriver;
01-05 22:27:57.035: W/System.err(1610): java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
01-05 22:27:57.055: W/System.err(1610): at java.lang.Class.classForName(Native Method)
01-05 22:27:57.055: W/System.err(1610): at java.lang.Class.forName(Class.java:234)
01-05 22:27:57.055: W/System.err(1610): at java.lang.Class.forName(Class.java:181)
01-05 22:27:57.055: W/System.err(1610): at at.security.jdbcsecuritydemo.MainActivity$jdbccoonect.doInBackground(MainActivity.java:51)
01-05 22:27:57.055: W/System.err(1610): at at.security.jdbcsecuritydemo.MainActivity$jdbccoonect.doInBackground(MainActivity.java:1)
01-05 22:27:57.065: W/System.err(1610): at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-05 22:27:57.065: W/System.err(1610): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-05 22:27:57.065: W/System.err(1610): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-05 22:27:57.065: W/System.err(1610): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-05 22:27:57.065: W/System.err(1610): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-05 22:27:57.075: W/System.err(1610): at java.lang.Thread.run(Thread.java:1019)
01-05 22:27:57.085: W/System.err(1610): Caused by: java.lang.VerifyError: oracle.jdbc.driver.OracleDriver
01-05 22:27:57.085: W/System.err(1610): ... 11 more
01-05 22:27:57.205: D/gralloc_goldfish(1610): Emulator without GPU emulation detected.

Answer 1:

Android的Java是甲骨文的Java不同。 其中一个主要的区别是类库,从Java标准版(SE)不同。

在你的情况这意味着ojdbc6.jar ,因为需要一定的Java SE类,但不适用于Android将不会在Android的Java环境中运行。 该错误消息提到javax.management.MBeanServer 。 但我敢肯定,这不是唯一的一个。

我不认为你可以ojdbc6.jar在Android上工作。 它已经令人惊讶的是ojdbc14.jar工作。 所以它呆在一起,或者重新设计你的应用程序通过中间服务器去。



文章来源: Android Oracle Database JDBC6