Android Oracle 数据库 JDBC6

Posted

技术标签:

【中文标题】Android Oracle 数据库 JDBC6【英文标题】:Android Oracle Database JDBC6 【发布时间】:2013-01-06 14:49:28 【问题描述】:

您好,我想创建一个到我的 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.

【问题讨论】:

【参考方案1】:

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

在您的情况下,这意味着 ojdbc6.jar 不会在 Android 的 Java 环境中运行,因为某些 Java SE 类是必需的,但在 Android 上不可用。错误消息提到javax.management.MBeanServer。但我很确定这不是唯一的。

我认为你不能让ojdbc6.jar 在 Android 上运行。 ojdbc14.jar 工作已经很令人惊讶了。因此,请继续使用它,或者重新设计您的应用以通过中间服务器运行。

【讨论】:

以上是关于Android Oracle 数据库 JDBC6的主要内容,如果未能解决你的问题,请参考以下文章

怎样启动JDBC Debug模式,打印JDBC诊断日志

oracle老提示限制连接数,怎样让oracle无限连接

如何查询oracle某个时间的连接数

求助#oracle数据库超出最大连接数

oracle 进程数 会话数一般是多少

怎样查看oracle当前的连接数