Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1619 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Connexion à une base oracle

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Connexion à une base oracle

n°1798297
Giz
Posté le 10-10-2008 à 14:21:24  profilanswer
 

Salut,
 
J'ai un programme de test de connection en java. Le getconnection plante :


at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:380)
   at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)
   at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:468)
   at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
   at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
   at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:839)
   at java.sql.DriverManager.getConnection(libgcj.so.7rh)
   at java.sql.DriverManager.getConnection(libgcj.so.7rh)
   at CheckJDBCInstallation_Oracle.getConnection(CheckJDBCInstallation_Oracle.java:13)
   at CheckJDBCInstallation_Oracle.main(CheckJDBCInstallation_Oracle.java:98)


 
 
Le code de base :
 

Code :
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5. public class CheckJDBCInstallation_Oracle {
  6.   public static Connection getConnection() throws Exception {
  7.     String driver = "oracle.jdbc.driver.OracleDriver";
  8.     String url = "jdbc:oracle:thin:@localhost:1521:alfresco";
  9.     String username = "alfresco";
  10.     String password = "alfresco";
  11.     Class.forName(driver); // load Oracle driver
  12.     Connection conn = DriverManager.getConnection(url, username, password);
  13.     return conn;
  14.   }
  15.   /**
  16.    * Test Validity of JDBC Installation
  17.    *  
  18.    * @param conn
  19.    *          a JDBC connection object
  20.    * @return true if a given connection object is a valid one; otherwise return
  21.    *         false.
  22.    * @throws Exception
  23.    *           Failed to determine if a given connection is valid.
  24.    */
  25.   public static boolean isValidConnection(Connection conn) throws Exception {
  26.     if (conn == null) {
  27.       // null connection object is not valid
  28.       return false;
  29.     }
  30.     if (conn.isClosed()) {
  31.       // closed connection object is not valid
  32.       return false;
  33.     }
  34.     // for Oracle database:
  35.     // you may use the connection object
  36.     // with query of "select 1 from dual";
  37.     // if the query returns the result, then
  38.     // it is a valid connection object.
  39.     return testConnection(conn, "select 1 from dual" );
  40.   }
  41.   /**
  42.    * Test Validity of a Connection
  43.    *  
  44.    * @param conn
  45.    *          a JDBC connection object
  46.    * @param query
  47.    *          a sql query to test against database connection
  48.    * @return true if a given connection object is a valid one; otherwise return
  49.    *         false.
  50.    */
  51.   public static boolean testConnection(Connection conn, String query) {
  52.     ResultSet rs = null;
  53.     Statement stmt = null;
  54.     try {
  55.       stmt = conn.createStatement();
  56.       if (stmt == null) {
  57.         return false;
  58.       }
  59.       rs = stmt.executeQuery(query);
  60.       if (rs == null) {
  61.         return false;
  62.       }
  63.       if (rs.next()) {
  64.         // connection object is valid: we were able to
  65.         // connect to the database and return something useful.
  66.         return true;
  67.       }
  68.       // there is no hope any more for the validity
  69.       // of the connection object
  70.       return false;
  71.     } catch (Exception e) {
  72.       return false;
  73.     } finally {
  74.       // close database resources
  75.       try {
  76.         rs.close();
  77.         stmt.close();
  78.       } catch (Exception e) {
  79.         // ignore
  80.       }
  81.     }
  82.   }
  83.   public static void main(String[] args) {
  84.     Connection conn = null;
  85.     try {
  86.       conn = getConnection();
  87.       System.out.println("conn=" + conn);
  88.       System.out.println("valid connection = " + isValidConnection(conn));
  89.     } catch (Exception e) {
  90.       // handle the exception
  91.       e.printStackTrace();
  92.       System.exit(1);
  93.     } finally {
  94.       // release database resources
  95.       try {
  96.         conn.close();
  97.       } catch (Exception e) {
  98.         // ignore
  99.       }
  100.     }
  101.   }
  102. }


 
j'ai crée le schema oracle dans les regles de l'art comme ici :
 
http://www.psoug.org/reference/schema.html
 
 
Que faire d'autres ?  
 
 
Aidez-moi plz, je suis chez le client pour lui installer son truc  [:ke-c]


Message édité par Elmoricq le 10-10-2008 à 14:23:18

---------------
Asus P5Q Pro | C2D E8400 3GHz@4GHz + Noctua NH-C12P | 2x2Go Patriot Extreme PC-8500 | GeForce GTX 460@Stock 1Go GLH | Crucial SSD M4 64Go Sata3
mood
Publicité
Posté le 10-10-2008 à 14:21:24  profilanswer
 

n°1798303
Giz
Posté le 10-10-2008 à 14:24:59  profilanswer
 

Ce tutorial jdbc/oracle dit la meme chose pourtant : http://w2.syronex.com/jmr/edu/db/oracle-and-java
 
:/


---------------
Asus P5Q Pro | C2D E8400 3GHz@4GHz + Noctua NH-C12P | 2x2Go Patriot Extreme PC-8500 | GeForce GTX 460@Stock 1Go GLH | Crucial SSD M4 64Go Sata3
n°1798368
brisssou
8-/
Posté le 10-10-2008 à 15:55:53  profilanswer
 

et puis c'est dommage, c'est la première ligne de ton exception qui est intéressante. celle que t'as pas mis


---------------
HFR - Mes sujets pour Chrome - Firefox - vérifie les nouveaux posts des topics suivis/favoris

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Connexion à une base oracle

 

Sujets relatifs
connexion base de donnees oracle via phpprobleme de connexion avec ma base oracle
problème connexion base de données oracleConnexion à une base Oracle Express 10g
Connexion Base Oracle en VBconnexion à une base oracle avec DBI
[oracle+php]connexion a la baseconnexion à une base de données oracle en vb excel
connexion à une base oracleCONNEXION PHP - ORACLE (base de données n'est pas sur serveur apache)
Plus de sujets relatifs à : Connexion à une base oracle


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR