Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. package com.example.testoracle;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7.  
  8. import android.app.Activity;
  9. import android.database.SQLException;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.view.Menu;
  13. import android.widget.TextView;
  14. import android.widget.Toast;
  15.  
  16.  
  17. public class MainActivity extends Activity {
  18.  
  19. @Override
  20. protected void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. try {
  23. String userName = getDataFromOraDB();
  24. TextView tv = new TextView(this);
  25. tv.setText("Here is the name : "+userName);
  26. setContentView(tv);
  27. } catch (SQLException e) {
  28. Toast.makeText(this, "1st toast : "+e.getMessage(), Toast.LENGTH_LONG).show();
  29. } catch (ClassNotFoundException e) {
  30. Toast.makeText(this, "second toast : "+e.getMessage(), Toast.LENGTH_LONG).show();
  31. }
  32. }
  33.  
  34. public String getDataFromOraDB() throws SQLException,
  35. ClassNotFoundException {
  36. String name = null;
  37. String jdbcURL = "jdbc:oracle:thin:@//localhost:1521:oracl";
  38. String user = "SYSTEM";
  39. String passwd = "root";
  40. // Load the Oracle JDBC driver
  41.  
  42. try {
  43. Log.w("MyApp","Try");
  44. DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
  45. Connection conn;
  46. ResultSet rs;
  47. Statement stmt;
  48. conn = DriverManager.getConnection(jdbcURL, user, passwd);
  49. stmt = conn.createStatement();
  50. Log.w("MyApp","Avant query");
  51. rs = stmt.executeQuery("select Name from table_people");
  52. Log.w("MyApp","Apres query");
  53. if (rs.next()) {
  54. name = rs.getString("Name");
  55. }
  56. } catch (java.sql.SQLException e) {
  57. // Auto-generated catch block
  58. System.out.println("the exception is : " + e.toString());
  59. }
  60.  
  61. Toast.makeText(getApplicationContext(), "3rd toast : "+name, Toast.LENGTH_LONG).show();
  62. return name;
  63. }
  64.  
  65. @Override
  66. public boolean onCreateOptionsMenu(Menu menu) {
  67. // Inflate the menu; this adds items to the action bar if it is present.
  68. getMenuInflater().inflate(R.menu.main, menu);
  69. return true;
  70. }
  71. }
  72.  
  73. <uses-permission android:name="android.permission.INTERNET" />
  74.  
  75. 06-01 15:16:34.142: W/MyApp(402): Try
  76. 06-01 15:16:34.373: I/dalvikvm(402): Failed resolving Loracle/jdbc/xa/OracleXAResource; interface 927 'Ljavax/transaction/xa/XAResource;'
  77. 06-01 15:16:34.373: W/dalvikvm(402): Link of class 'Loracle/jdbc/xa/OracleXAResource;' failed
  78. 06-01 15:16:34.373: W/dalvikvm(402): Unable to resolve superclass of Loracle/jdbc/xa/client/OracleXAResource; (1341)
  79. 06-01 15:16:34.373: W/dalvikvm(402): Link of class 'Loracle/jdbc/xa/client/OracleXAResource;' failed
  80. 06-01 15:16:34.373: W/dalvikvm(402): Unable to resolve superclass of Loracle/jdbc/driver/T4CXAResource; (1348)
  81. 06-01 15:16:34.373: W/dalvikvm(402): Link of class 'Loracle/jdbc/driver/T4CXAResource;' failed
  82. 06-01 15:16:34.373: W/dalvikvm(402): VFY: unable to find class referenced in signature (Loracle/jdbc/driver/T4CXAResource;)
  83. 06-01 15:16:34.373: I/dalvikvm(402): Failed resolving Loracle/jdbc/xa/OracleXAResource; interface 927 'Ljavax/transaction/xa/XAResource;'
  84. 06-01 15:16:34.383: W/dalvikvm(402): Link of class 'Loracle/jdbc/xa/OracleXAResource;' failed
  85. 06-01 15:16:34.383: W/dalvikvm(402): Unable to resolve superclass of Loracle/jdbc/xa/client/OracleXAResource; (1341)
  86. 06-01 15:16:34.383: W/dalvikvm(402): Link of class 'Loracle/jdbc/xa/client/OracleXAResource;' failed
  87. 06-01 15:16:34.383: W/dalvikvm(402): Unable to resolve superclass of Loracle/jdbc/driver/T4CXAResource; (1348)
  88. 06-01 15:16:34.383: W/dalvikvm(402): Link of class 'Loracle/jdbc/driver/T4CXAResource;' failed
  89. 06-01 15:16:34.383: I/dalvikvm(402): Could not find method oracle.jdbc.driver.T4CXAResource.setPasswordInternal, referenced from method oracle.jdbc.driver.T4CConnection.getPasswordInternal
  90. 06-01 15:16:34.383: W/dalvikvm(402): VFY: unable to resolve virtual method 10574: Loracle/jdbc/driver/T4CXAResource;.setPasswordInternal (Ljava/lang/String;)V
  91. 06-01 15:16:34.533: I/dalvikvm(402): Failed resolving Loracle/jdbc/pool/OracleDataSource; interface 850 'Ljavax/naming/Referenceable;'
  92. 06-01 15:16:34.533: W/dalvikvm(402): Link of class 'Loracle/jdbc/pool/OracleDataSource;' failed
  93. 06-01 15:16:34.533: I/dalvikvm(402): Could not find method oracle.jdbc.pool.OracleDataSource.filterConnectionProperties, referenced from method oracle.jdbc.driver.PhysicalConnection.getProperties
  94. 06-01 15:16:34.533: W/dalvikvm(402): VFY: unable to resolve static method 11805: Loracle/jdbc/pool/OracleDataSource;.filterConnectionProperties (Ljava/util/Properties;)Ljava/util/Properties;
  95. 06-01 15:16:34.543: W/dalvikvm(402): VFY: unable to find class referenced in signature (Ljavax/transaction/xa/XAResource;)
  96. 06-01 15:16:35.192: I/System.out(402): the exception is : java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
  97.  
  98. Net Address (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522)) Connect to port 1522
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement