2012-02-22 16 views
0

我想連接的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); 
    } 

回答

0

你的表名是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(); 

希望這有助於