android odbc connection

Posted by Vijay Kumar on Stack Overflow See other posts from Stack Overflow or by Vijay Kumar
Published on 2012-03-19T18:01:45Z Indexed on 2012/03/19 18:03 UTC
Read the original article Hit count: 369

Filed under:
|
|

i want to connect odbc connection for my android application. Here in my program i'm using oracle database 11g and my table name is sample. After i run the program close the emulator open the database the values could not be stored. Please give one solution or any changes in my program or connection string.

    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:@localshot: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);

    }
}
  }

© Stack Overflow or respective owner

Related posts about android

Related posts about string