Android和ODBC
问题描述:
我想连接的Oracle 11g数据库到我的Android应用程序的ODBC连接。在我的程序中,我想将两个字符串存储到oracle数据库中。我的表名是name1
。在打开表格后运行该程序后,无法存储值。Android和ODBC
package com.odbc;
import java.sql.Connection;
import java.sql.DriverManager;
import android.app.Activity;
import android.os.Bundle;
import java.sql.*;
public class OdbcdemoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
String first="kumar";
String last="vijay";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student","system","water");
PreparedStatement pst=con.prepareStatement("insert into student values(?,?)");
pst.setString(1,first);
pst.setString(2,last);
pst.executeUpdate();
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
答
你的表名是name1
,但你将数据插入到student
?
尝试以下操作:
Connection con=DriverManager.getConnection("jdbc:odbc:student","system","water");
PreparedStatement pst=con.prepareStatement("insert into name1 (colname1, colname2) values(?,?)");
pst.setString(1,first);
pst.setString(2,last);
pst.executeUpdate();
希望这有助于