Android的JDBC ODBC连接 [英] android jdbc odbc connection

查看:170
本文介绍了Android的JDBC ODBC连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到我的android应用ODBC连接。我的数据库是Oracle 10g中。在这里,在我的code我的表名是世界。编译我的程序,并关闭仿真器打开的表在Oracle数据库后的值不能被存储

i want to connect odbc connection to my android application. my database is oracle 10g. Here in my code my table name is world. After compiling my program and close the emulator open table in oracle database the values could not be stored

相同的编码我编译正常javac编译器在CMP提示值应该被存储,如果我在编译Android应用程序在Eclipse IDE中的值不能stored.Pls给出一个解决方案,或在我的code的任何变化 提前致谢     包com.odbc;

The same coding i compiled normal javac compiler in cmp prompt the values should be stored, if i compiling in android application in eclipse ide the values could not be stored.Pls give one solution or any changes in my code Thanks in advance package com.odbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import android.app.Activity;
import android.os.Bundle;
import android.R.id;

public class OdbcActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try
    {
        String country="india";
        String city="delhi";
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:world","system","love");
        PreparedStatement ps=con.prepareStatement("insert into world(country,city) values(?,?)");
        ps.setString(1,country);
        ps.setString(2,city);
        ps.executeUpdate();



    }
    catch(Exception e)
    {
        System.out.println("Exception:"+e);
    }
}

}

推荐答案

直接连接到DMBS Android应用程序是不是一个建筑,我建议。相反,我建议设置在服务器上的应用程序(使用Java,Rails的,等等),读取数据库,并公开为Android应用程序来获得数据的简单HTTP Web服务。这不仅是一个更合理的架构,我甚至不能确定,你可以在Android设备上运行的JDBC驱动程序。用我的建筑,你从你的数据库的结构和类型的隔离器件。

Android apps connecting directly to a DMBS isn't an architecture I'd recommend. Instead, I suggest setting an application on the server (using Java, Rails, whatever) that reads the database and exposes a simple HTTP web service for the Android app to get at the data. Not only is that a more sound architecture, I'm not even sure you can run JDBC drivers in an Android device. Using my architecture, you isolate the device from the structure and type of your database.

这篇关于Android的JDBC ODBC连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆