android jdbc odbc 连接 [英] android jdbc odbc connection

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

问题描述

我想将 odbc 连接连接到我的 android 应用程序.我的数据库是oracle 10g.在我的代码中,我的表名是 world.编译我的程序并关闭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

我在 cmp 中编译普通 javac 编译器的相同编码提示应该存储值,如果我在 eclipse ide 中的 android 应用程序中编译,则无法存储值.请提供一种解决方案或对我的代码进行任何更改提前致谢包 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天全站免登陆