android odbc连接
问题描述:
我想为我的android应用程序连接odbc连接。在我的程序中,我使用的是Oracle数据库11g,而我的表名是示例。我运行程序关闭模拟器后打开数据库的值不能被存储。请给我一个解决方案或我的程序或连接字符串中的任何更改。android odbc连接
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);
}
}
}
答
不要使用本地主机中的connectionString,因为它代表实际的设备或emulator.Please添加在您运行Oracle的系统的IP地址。
+0
感谢您的指导。它帮助我成功储存了很多东西 – 2012-03-22 13:24:05
[android jdbc odbc连接]可能重复(http://stackoverflow.com/questions/9440532/android-jdbc-odbc-connection) – Esailija 2012-07-16 18:34:56