1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.sobi.test;
import com.sobi.Exception.SobiConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.olap4j.OlapConnection;
import org.olap4j.OlapWrapper;
/**
*
* @author Bezalel
*/
public class Test {
private static final String FICHIER_PROPERTIES = "com/sobi/dao/Sobi.properties";
private static final String PROPERTY_URL = "url";
private static final String PROPERTY_DRIVER = "driver";
private static final String PROPERTY_NOM_UTILISATEUR = "nomutilisateur";
private static final String PROPERTY_MOT_DE_PASSE = "motdepasse";
private String url;
private String username;
private String password;
/**
* @param args the command line arguments
* @throws java.sql.SQLException
*/
public static void main(String[] args) throws SQLException {
getInstance();
}
public static void getInstance() throws SobiConfigurationException, SQLException {
Properties properties = new Properties();
String url;
String driver;
String nomUtilisateur;
String motDePasse;
String domaine = "WINSERVER" ;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream fichierProperties = classLoader.getResourceAsStream(FICHIER_PROPERTIES);
if (fichierProperties == null) {
throw new SobiConfigurationException("Le fichier properties " + FICHIER_PROPERTIES + " est introuvable.");
}
try {
System.out.println("LOAD FILE");
properties.load(fichierProperties);
System.out.println("LOAD FILE OK");
url = properties.getProperty(PROPERTY_URL);
driver = properties.getProperty(PROPERTY_DRIVER);
nomUtilisateur = properties.getProperty(PROPERTY_NOM_UTILISATEUR);
motDePasse = properties.getProperty(PROPERTY_MOT_DE_PASSE);
System.out.println(url);
System.out.println(driver);
System.out.println(nomUtilisateur);
System.out.println(motDePasse);
} catch (IOException e) {
throw new SobiConfigurationException("Impossible de charger le fichier properties " + FICHIER_PROPERTIES, e);
}
try {
Class.forName(driver);
System.out.println("SUCCESS LOAD DRIVER");
} catch (ClassNotFoundException e) {
throw new SobiConfigurationException("Le driver est introuvable dans le classpath.", e);
}
try {
System.out.println("ESSAI D'ETABLISSEMENT D'UNE CONNEXION");
Connection con = DriverManager.getConnection(url,nomUtilisateur,motDePasse) ;
System.out.println("CONNEXION OK");
OlapConnection olap = (OlapConnection)con; // MON PROBLEME SE SITUE A CE NIVE
OlapWrapper wrapper = (OlapWrapper)olap ;
OlapConnection olapConnection = wrapper.unwrap(OlapConnection.class);
} catch (SQLException et) {
throw new SobiConfigurationException("CONNEXION IMPOSSIBLE .", et);
}
}
} |
Partager