【发布时间】: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