1. Check out our companion app, Forums for Android! Download from Google Play

Oracle database connection using jbdc

Discussion in 'Application Development' started by mogly, Apr 10, 2011.

  1. mogly

    mogly New Member
    Thread Starter
    5

    Apr 10, 2011
    1
    0
    5
    Hi all :)
    I am trying to communicate with an oracle database using jbdc, I need to read and write to the database, I dont have server access so have to commincate directly with the database. At the moment I am struggling to even get a connection. The app only needs to be simulated on a secure network so I am not too worried about security issues.
    code im using:
    Code (Text):
    1. package com.tentantrepairs;
    2.  
    3. import java.sql.Connection;
    4. import java.sql.DriverManager;
    5. import android.app.Activity;
    6. import android.os.Bundle;
    7. import android.widget.TextView;
    8.  
    9. public class TenantRepairs extends Activity{
    10.     @Override
    11.     public void onCreate(Bundle savedInstanceState) {
    12.     super.onCreate(savedInstanceState);
    13.     TextView tv = new TextView(this);
    14.     tv.setText("orcale Connect Example.");
    15.     setContentView(tv);
    16.    
    17.     Connection conn;
    18.     String url = "jdbc:oracle:thin:@blah.blah.blah.ac.uk:1522:orcl";
    19.     String userName = "PRCSF";
    20.     String password = "PRCSF";
    21.     try {
    22.         Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    23.       conn = DriverManager.getConnection(url,userName,password);
    24.       tv.setText("Connected to the database");
    25.     } catch (Exception e) {
    26.         tv.setText("nope");
    27.     }
    28.     }
    29.     }
    Many thanks Ben
     

    Advertisement

Share This Page

Loading...