5 Replies Latest reply: Jul 12, 2012 2:49 AM by gimbal2 RSS

    JDBC connection between android and oracle apps

    926625

      Hello.
      I am new to oracle apps and android. But the coding of android is in java.
      I want to create a application in which i want to connect oracle apps with my application of android written in java.
      I am sending code which is not working but not having error too.

      **************************** Connection class ******************************

      import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class getConnection { public static Connection getDBConnection(){     Connection con;     con=null;     try{         Class.forName("oracle.jdbcdriver.OracleDriver");     } catch (ClassNotFoundException e) {         System.out.println(e);     }     try {         String url="Host String:1523:SID";         con=DriverManager.getConnection(url,"XXXX","XXXX");                 if(con!=null){             System.out.println("Connection Successfull..."+"\n");         }else{             System.out.println("Connection Failed.....");         }     } catch (SQLException e) {         System.out.println(e);     }     return(con); } }

      ******************************** Main CLass *************************************

      import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import android.os.Bundle; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; public class Main extends Activity implements OnClickListener{ private EditText etUsername;     private EditText etPassword;     private Button btnLogin;     private Button btnCancel;     private TextView lblResult; /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                 etUsername = (EditText)findViewById(R.id.username);         etPassword = (EditText)findViewById(R.id.password);         btnLogin = (Button)findViewById(R.id.login_button);         btnCancel = (Button)findViewById(R.id.cancel_button);         lblResult = (TextView)findViewById(R.id.result);             btnLogin.setOnClickListener (new OnClickListener() {         public void onClick(View v) {         Connection con = null;                 PreparedStatement stmt = null;                 ResultSet rs = null;                 int n=0;                 lblResult.setText("Hello.");                 con=getConnection.getDBConnection();                 lblResult.setText("After Connection");                 String query = "select object_id from all_objects where object_id=18";                         try {                     stmt = con.prepareStatement(query);                 } catch (SQLException e) {                     // TODO                     System.out.println(e);                 }                 try {                     rs = stmt.executeQuery();                 } catch (SQLException e) {                     // TODO                     System.out.println(e);                 }                 try {                     while(rs.next()){                         n = rs.getInt("OBJECT_ID");                     }                 } catch (SQLException e) {                     // TODO                     System.out.println(e);                 }                                 // Check Login         String username = etUsername.getText().toString();         String password = etPassword.getText().toString();                         if(username.equals("U_Name") && password.equals("Pass") && n==18){         lblResult.setText("Login successful.");         } else {             lblResult.setText("Login failed. Username and/or password doesn't match.");             }         }         });         btnCancel.setOnClickListener(new OnClickListener() {         //@Override         public void onClick(View v) {             // Close the application             finish();         }         });     } public void onClick(View v) { // TODO Auto-generated method stub } }

      I am doing this in Eclipse.
      Help me out as soon as possible.

      Thank You.

      Edited by: EJP on 12/07/2012 16:05: added {noformat}

      {noformat} tags. Please use them.