IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JDBC Java Discussion :

Problème de connexion à une BDD HSQLDB


Sujet :

JDBC Java

  1. #1
    Membre régulier Avatar de Mr.Robot12
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    189
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 189
    Points : 81
    Points
    81
    Par défaut Problème de connexion à une BDD HSQLDB
    Bonjour,

    j'ai un souci et je ne comprends pas pourquoi j'ai cette erreur.
    je m'explique : je travaille sur un grand projet qui n'a pas été fait pas moi, j'essaie de mettre en place une BDD HSQLDB au lieu de ORACLE pour avoir une BDD embarquée (c'est mon tuteur de stage qui m'a demandé de le faire)

    il y a un fichier "parameter-eclipse.properties" dans lequel j'ai remplacé par ça (avant c'était sur oracle)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    appli.db.driver=org.hsqldb.jdbcDriver
    appli.db.url=jdbc:hsqldb:file:database
    appli.db.user=sa
    appli.db.pwd=
    appli.db.schema=
    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    public class AutorisationTest
    {
        private Connection cn = null;
     
      @Before
      public void setUp() throws Exception
      {
        //super();
        try
        {
            Class.forName("org.hsqldb.jdbcDriver");
            cn = DriverManager.getConnection("jdbc:hsqldb:file:database;shutdown=true", "sa", "");
            Statement statement = cn.createStatement();
            statement.execute("SET DATABASE SQL SYNTAX ORA TRUE");
            statement.close();
        }
        catch (ClassNotFoundException | SQLException e)
        {
            e.printStackTrace();
        }
      }
     
        @Test
        public void test()
        {
            try
            {
     
                BatchStarter batchStarter = new fr.xxx.xxxx.xxx.batch.BatchStarter();
     
                String args[] = {"traitementautorisation"};
     
                batchStarter.main(args);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
     
            //quand je test cette partie ça marche mais quand je test ce qu'il y a juste avant ça ne marche pas
            /*Statement statement;
            try
            {
                statement = cn.createStatement();
                statement.executeUpdate("CREATE TABLE IF NOT EXISTS test (colonne1 INT, colonne2 INT)");
                for(int i=0; i<= 10; i++) {
                    statement.executeUpdate("insert into test values ('"+i+"', '"+i+"')");
                }
                statement.close();
                DatabaseManagerSwing manager = new DatabaseManagerSwing();
                manager.main();
                manager.connect(cn);
                manager.start();
                //cn.close();
            }
            catch (SQLException e)
            {
            }*/
     
     
        }
    }

    l'erreur que j'ai : org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: L'URL Oracle indiquée n'est pas valide
    pourquoi il cherche oracle alors que j'ai mis HSQLDB ?

    quelqu'un peut m'aider svp

  2. #2
    Membre régulier Avatar de Mr.Robot12
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    189
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 189
    Points : 81
    Points
    81
    Par défaut
    je ne comprends absolument rien à la structure de l'appli
    j'ai fais plein de recherches et j'ai fais ça :
    dans le fichier web.xml
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
        <context-param>
            <param-name>spring.profiles.active</param-name>
            <param-value>embedded</param-value>
        </context-param>

    et ça c'est dans un fichier qui s'appelle batchContext-resources.xml :
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    <beans profile="embedded">
     
                <bean id="jobRepository"
                    class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
                    <property name="dataSource" ref="datasource" />
                    <property name="transactionManager" ref="transactionManager" />
                    <property name="databaseType" value="hsql" />
                </bean>
     
                <jdbc:initialize-database data-source="datasource">
                    <jdbc:script location="classpath:org/springframework/batch/core/schema-hsqldb.sql" />
                </jdbc:initialize-database>
     
            </beans>

    c'était expliqué dans le web.xml du framework qu'ils utilisent en interne :
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    ApplicationContext: Le fragment web lombok active uniquement le profile postgre (pour des sources de donnees postgresql). <context-param> 
        <param-name>spring.profiles.active</param-name> <param-value>postgre</param-value> </context-param> Si vous utilisez une base de données oracle 
        ou une base de données embarquée hsqldb, vous devez alors activer le profil correspondant: oracle ou embedded en redifinissant le parametre spring.profiles.active

    je ne comprends pas pourquoi il va toujours chercher Oracle

  3. #3
    Expert confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 937
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 937
    Points : 4 358
    Points
    4 358
    Par défaut
    Qu'est-ce qui vous fais croire que web.xml est utilisé par un test unitaire ?

  4. #4
    Membre régulier Avatar de Mr.Robot12
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    189
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 189
    Points : 81
    Points
    81
    Par défaut
    Citation Envoyé par Mr.Robot12 Voir le message
    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    ApplicationContext: Le fragment web lombok active uniquement le profile postgre (pour des sources de donnees postgresql). <context-param> 
        <param-name>spring.profiles.active</param-name> <param-value>postgre</param-value> </context-param> Si vous utilisez une base de données oracle 
        ou une base de données embarquée hsqldb, vous devez alors activer le profil correspondant: oracle ou embedded en redifinissant le parametre spring.profiles.active
    c'était écrit ici du coup j'ai essayé comme ça, mais il s'avère ça change rien.
    ce que j'ai fais du coup j'ai changé <beans profile="embedded"> en <beans profile="oracle"> et après il prenait bien le HSQL.
    vu que je ne comprends pas la structure j'arrive pas à voir où c'est indiqué qu'il faut utiliser oracle

  5. #5
    Expert confirmé
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 937
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 937
    Points : 4 358
    Points
    4 358
    Par défaut
    Il y a plusieurs façon de définir le profil Spring actif dans un test unitaire MAIS web.xml ne fait pas partie des options :
    lui ne sera utilisé que lors du déploiement du WAR/EAR, donc éventuellement en test d'intégration mais pas en test unitaire.

    Pour un test unitaire, utilisez un fichier .properties, l'annotation @ActiveProfiles, l'annotation @TestPropertySource, via l'environnement, ...

  6. #6
    Membre régulier Avatar de Mr.Robot12
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    189
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 189
    Points : 81
    Points
    81
    Par défaut
    je vais essayer ça merci

  7. #7
    Membre régulier Avatar de Mr.Robot12
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2016
    Messages
    189
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2016
    Messages : 189
    Points : 81
    Points
    81
    Par défaut
    j'ai une erreur que je ne comprend pas : quand je lance en test unitaire tout marche nickel mais quand je lance le projet en web j'ai une exception :

    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jdbc.datasource.init.DataSourceInitializer#0': Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.hsqldb.JDBCDriver'
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
    	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)
    	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    	at java.lang.Thread.run(Thread.java:745)
    Caused by: org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.hsqldb.JDBCDriver'
    	at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:61)
    	at org.springframework.jdbc.datasource.init.DataSourceInitializer.execute(DataSourceInitializer.java:108)
    	at org.springframework.jdbc.datasource.init.DataSourceInitializer.afterPropertiesSet(DataSourceInitializer.java:93)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
    	... 21 more
    Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.hsqldb.JDBCDriver'
    	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    	at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:46)
    	... 25 more
    Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.hsqldb.JDBCDriver'
    	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)
    	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    	... 26 more
    Caused by: java.lang.ClassNotFoundException: org.hsqldb.JDBCDriver
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:190)
    	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1130)
    	... 29 more

    je ne comprends pas pourquoi ça fais ça parce que en TU ça marche. en plus j'ai ajouté la dépendance dans pom.xml depuis le début.
    vous pouvez m'aider svp

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. problème de connexion à une BDD en ISAPI
    Par skywaukers dans le forum Connexion aux bases de données
    Réponses: 1
    Dernier message: 13/06/2015, 21h26
  2. Réponses: 3
    Dernier message: 07/05/2013, 19h26
  3. Problème de connexion à une BDD ASA 7 sous Win7
    Par Mirande dans le forum Sybase
    Réponses: 0
    Dernier message: 28/12/2012, 17h13
  4. Problème de connexion à une BDD SQL SERVER 2008
    Par idris dans le forum Accès aux données
    Réponses: 1
    Dernier message: 08/09/2010, 16h37
  5. [MySQL] Problème de connexion à une BDD distante
    Par maxopoulos dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 19/04/2006, 10h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo