【问题标题】:android odbc connection安卓 odbc 连接
【发布时间】:2012-03-19 18:01:45
【问题描述】:

我想为我的 android 应用程序连接 odbc 连接。在我的程序中,我使用的是 oracle 数据库 11g,我的表名是 sample。运行程序后关闭模拟器打开数据库,无法存储值。请给出一个解决方案或我的程序或连接字符串中的任何更改。

    package com.odbc;

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

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

      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);
    String first="vijay";
    String last="kumar";
        try
    {
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
            Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","vijay");
            PreparedStatement pst=con.prepareStatement("insert into sample(first,last) values(?,?)");
            pst.setString(1,first);
            pst.setString(2,last);
            pst.executeUpdate();

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

    }
}
  }

【问题讨论】:

标签: android string connection odbc


【解决方案1】:

在connectionString中不要使用localhost,因为它代表实际的设备或模拟器。请添加运行oracle的系统的IP地址。

【讨论】:

  • 感谢您的指导。它帮助我成功存储了很多
猜你喜欢
  • 1970-01-01
  • 2011-05-13
  • 2012-05-26
  • 2010-11-02
  • 1970-01-01
  • 2011-05-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多