Android Oracle Database JDBC6

2019-03-04 23:07发布

问题:

Hi i want to create a connection to my Oracle database. i previously used ojdbc14.jar and everything was working fine, but the connection should be secure and i want to encrypt the files. so i decided to use ojdbc5.jar now. the jar is im my "libs" folder

Reasons for changing from jdbc14 to jdbc6 i want to use Properties for a secure data exchange between my DB and my devices

earlier i also tried jdbc5 but with this i only got a java Heap Size error.

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

    }

}

ERROR:

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.

回答1:

Android's Java is different from Oracle's Java. One of the main differences is the class library that differs from the Java Standard Edition (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.