Connexion java oracle

Signaler
Messages postés
2
Date d'inscription
jeudi 22 novembre 2007
Statut
Membre
Dernière intervention
22 mai 2008
-
Messages postés
182
Date d'inscription
jeudi 14 juillet 2005
Statut
Membre
Dernière intervention
14 mars 2011
-
bonjour,


j'essai de faire une connexion java oracle 8i, et ça marche pas. j'ai telecharger la classe12.
voici les erreurs:
oracle.net.TNSAddress.SOException
 at oracle.net.TNSAddress.ServiceAlias.initFromNVPair(Unknown Source)
 at oracle.net.TNSAddress.ServiceAlias.initFromString(Unknown Source)
 at oracle.net.resolver.AddrResolution.resolveAddrTree(Unknown Source)
 at oracle.net.resolver.AddrResolution.resolveAndExecute(Unknown Source)
 at oracle.net.ns.NSProtocol.establishConnection(Unknown Source)
 at oracle.net.ns.NSProtocol.connect(Unknown Source)
 at oracle.jdbc.ttc7.TTC7Protocol.connect(TTC7Protocol.java:1213)
 at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:209)
 at oracle.jdbc.driver.OracleConnection.(OracleConnection.java:252)
 at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
 at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
 at java.sql.DriverManager.getConnection(DriverManager.java:525)
 at java.sql.DriverManager.getConnection(DriverManager.java:171)
 at base.connexionBD(base.java:41)
 at base.main(base.java:81)
 at __SHELL1.run(__SHELL1.java:7)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at bluej.runtime.ExecServer$3.run(ExecServer.java:792)
java.lang.NullPointerException
 at base.select(base.java:55)
 at base.main(base.java:82)
java.lang.NullPointerException
 at base.select(base.java:55)
 at base.main(base.java:82)
java.lang.NullPointerException
 at base.select(base.java:55)
 at base.main(base.java:82)
java.lang.NullPointerException
 at base.select(base.java:55)
 at base.main(base.java:82)

1 réponse

Messages postés
182
Date d'inscription
jeudi 14 juillet 2005
Statut
Membre
Dernière intervention
14 mars 2011

voila une classe qui te permet dete connecet a plusieur DB
Mysql,Oracle ...

/*
* jconndb.java
*
* Created on 1 janvier 1999, 01:18
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package iutacad;

/**
*
* @author Thierry Bekola
*/
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.lang.String;

/**
* Titre :
* Description :
* Copyright : Copyright (c) 2007
* Société :
* @author
* @version 1.0
*/


public class jconndb {

private String Host;
private String User;
private String Password;
private String Database;
private String DatabaseSID;
private String Driver;
private Connection StringConnexion;
private String UrlConnexion;
private ResultSet resultat;
protected String message;
private int port;

public jconndb() {

this.Driver = null;
this.Database =null;
this.StringConnexion = null;
this.UrlConnexion =null;


}
public void set_param_connexion(){
/*
relatif a la connexion par defautl
*/
this.Host ="localhost"; //hote
this.Password ="";//password
this.User ="root";//username
this.Database ="konkerordb"; //nomdab pour mysql
this.DatabaseSID ="iutacad"; //Sid pour Oracle
this.port =3306;
}
public Connection get_StringConnexion(){
return this.StringConnexion;
}
//accesseur des propriete privee
public void set_port(int myport){
this.port = myport;
String matsrt = new String("toto");
// matsrt.e
}
public void set_host(String Myhost){
this.Host = Myhost;
}
public void set_user(String Myuser){
this.User = Myuser;
}
public void set_password(String Mypassword){
this.Password = Mypassword;
}
public void set_database(String Mydatabase){
this.Database = Mydatabase;
}
public void set_databaseSID(String MydatabaseSID){
this.DatabaseSID = MydatabaseSID;
}
public void set_driver(String Mydriver){
this.Driver = Mydriver;
}
public String get_message(){
return this.message;
}
public ResultSet get_resultat(){
return this.resultat;
}
// pilote JDBC Mysql
public String get_mysql_driver_JDBC(){
this.UrlConnexion ="jdbc:mysql://"+this.Host+"/"+
this.Database+"?user="+this.User+
"&password="+this.Password;
return "com.mysql.jdbc.Driver";

}
// pilote JDBC Oracle
public String get_oracle_driver_JDBC(){
this.UrlConnexion ="jdbc:oracle:thin:@"+ this.Host+":"+this.port+":"+this.DatabaseSID;
return "oracle.jdbc.driver.OracleDriver";
}

//pilote ODBC_JDBC
public String get_driver_ODBC_JDBC(){
this.UrlConnexion ="jdbc:odbc:"+this.Database;
return "sun.jdbc.odbc.JdbcOdbcDriver";
}
//pilote odbc postgrelsql
public String get_driver_ODBC_JDBC_Postgrel(){
return "postgrelsql.Driver";
}
//chargement du pilotes
public void LoadDriver()
{
try{
Class.forName(this.Driver).newInstance();
this.message = "Chargement Reussi";
System.out.println("Chargement Reussi");
}catch(Exception ex){
System.out.println(ex.getMessage());
this.message = ex.getMessage();
// JOptionPane.showMessageDialog(null,"Impossible de charger le driver","Kadresse Warning !",JOptionPane.ERROR_MESSAGE );
// System.exit(0);
}
}

public void OpenConnexion(){
try{
if(this.Driver.equals("oracle.jdbc.driver.OracleDriver")){
this.StringConnexion = DriverManager.getConnection(this.UrlConnexion,this.User,this.Password);
}
else{
this.StringConnexion = DriverManager.getConnection(this.UrlConnexion);
}
System.out.println("Connexion reussi");
this.message = "Connexion reussi";
}catch(Exception ex){
// JOptionPane.showMessageDialog(null,"Impossible de se Connecter au serveur","Kadresse Warning !",JOptionPane.ERROR_MESSAGE );
System.out.println(ex.getMessage());
this.message =ex.getMessage();
// System.exit(0);
}
}
//fermeture de la connexion
public void CloseConnexion()
{
try{

this.resultat.close();
System.out.println("Connexion fermer");
}catch(Exception MysqlEx){
System.out.println("Impossible de fermer");
// JOptionPane.showMessageDialog(null,"Impossible de fermer","Kadresse Warning !",JOptionPane.ERROR_MESSAGE );
}
}
public void set_Request(String MyRequest)
{

String Request = new String(MyRequest);
try{
Statement stmt = this.StringConnexion.createStatement();
this.resultat = stmt.executeQuery(Request);
}catch(Exception ex){
System.out.println( ex.getMessage());
}
}

}


pour l utiliser tu dev une classse classe herite de cette classe


ex
public class userb extends jconndb {
public userb() {
this.set_param_connexion();
this.set_driver(this.get_oracle_driver_JDBC());//chargement du pilote por oracle
this.LoadDriver();
this.OpenConnexion();
this.CloseConnexion();

}
}