0

您好我想创建到我的 Oracle 数据库的连接。我以前使用过 ojdbc14.jar,一切正常,但连接应该是安全的,我想加密文件。所以我决定现在使用 ojdbc5.jar。jar 是我的“libs”文件夹

从 jdbc14 更改为 jdbc6 的原因我想使用属性在我的数据库和我的设备之间进行安全的数据交换

早些时候我也尝试过 jdbc5,但是我只得到了一个 java Heap Size 错误。

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.
4

1 回答 1

2

Android 的 Java 与 Oracle 的 Java 不同。主要区别之一是与 Java 标准版 (SE) 不同的类库。

In your case that means that ojdbc6.jar won't run in Android's Java environment because certain Java SE classes are required but not available on Android. The error message mentions javax.management.MBeanServer. But I'm pretty sure that's not the only one.

I don't think you can make ojdbc6.jar work on Android. It's already surprising that ojdbc14.jar works. So stay with it, or redesign your app to go via an intermediary server.

于 2013-01-06T16:54:50.473 回答