Hi Richard,

I solved it on my own last week.

In my mind the solution was that I added a <resources></resources> around the 
content of the resources.xml.

1) I used Java 17 instead of Java 8.
2) I updated the org.apache.tomee:jakartaee-api and modfied the namespace code
3) I updated the maven-war-plugin 

mvn -e clean install tomee:run
curl http://localhost:8080/jdbc-servlet/
JDBC Connection is valid @ timestamp = 1686141982875

=> At the first glace the example result worked as expected.

4) I add more logging data to see that the correct driver is used

mvn -e clean install tomee:run
curl http://localhost:8080/jdbc-servlet/
Metadata at: SA
Metadata at: HSQL Database Engine Driver
Metadata at: 2.7.1

 JDBC Connection is valid @ timestamp = 1686141982875

=> To my surprise the code does not use Derby driver as I was expected.

5) I added the <resources> tag into the resources.xml.

mvn -e clean install tomee:run

curl http://localhost:8080/jdbc-servlet/
Metadata at: admin
Metadata at: Apache Derby Embedded JDBC Driver
Metadata at: 10.14.2.0 - (1828579)

 JDBC Connection is valid @ timestamp = 1686142146792

=> Now the correct database was used.

I published the modified code here:
https://github.com/abstract-thinking/tomee-9-jdbc-configuration-example/

Take a look inside the commit history because I was a little be confused by my 
own what I have done last week and about the fact that after the third step the 
result looked fine.

Cheers,
Markus



> Gesendet: Dienstag, 06. Juni 2023 um 13:08 Uhr
> Von: "Richard Zowalla" <r...@apache.org>
> An: users@tomee.apache.org
> Betreff: Re: How to Configure JDBC Web-INF resource with TomEE 9
>
> Hi,
> 
> can you push a small code example to GitHub?
> would make it much easier to point you into the right direction.
> 
> Gruß
> Richard
> 
> Am Dienstag, dem 30.05.2023 um 13:28 +0200 schrieb tomee-u...@web.de:
> > Hello,
> > 
> > I'm looking for an example hot two configure JDBC with Tomee 9.0.
> > 
> > First I read this article and the example works as expected.
> > https://www.tomitribe.com/blog/configuring-jdbc-in-tomee/
> > 
> > Then I tried to use TomEE 9.0 and MSSQL. [1]
> > 
> > On the first glance it looked successful because the string was given
> > as output. By a closer look not a connection to MSSQL was set up,
> > instead HSQL was used. [2][3]
> > 
> > Does anybody can point me to an example using WEB-
> > INF/resources.xml[4] and ToMEE 9?
> > 
> > Thanks,
> > Markus
> > 
> > [1]
> > 
> >     <properties>
> >         <maven.compiler.source>17</maven.compiler.source>
> >         <maven.compiler.target>17</maven.compiler.target>
> >         <project.build.sourceEncoding>UTF-
> > 8</project.build.sourceEncoding>
> >     </properties>
> > 
> >     <dependencies>
> >         <dependency>
> >             <groupId>org.apache.tomee.bom</groupId>
> >             <artifactId>tomee-plus</artifactId>
> >             <version>9.0.0</version>
> >             <scope>provided</scope>
> >         </dependency>
> >     </dependencies>
> > 
> >     <build>
> >         <finalName>jdbc-servlet</finalName>
> >         <plugins>
> >             <plugin>
> >                 <groupId>org.apache.maven.plugins</groupId>
> >                 <artifactId>maven-war-plugin</artifactId>
> >                 <version>3.3.2</version>
> >             </plugin>
> >             <plugin>
> >                 <groupId>org.apache.tomee.maven</groupId>
> >                 <artifactId>tomee-maven-plugin</artifactId>
> >                 <version>9.0.0</version>
> >                 <configuration>
> >                     <libs>
> >                         <lib>com.microsoft.sqlserver:mssql-
> > jdbc:9.2.0.jre8</lib>
> >                     </libs>
> >                     <tomeeClassifier>plus</tomeeClassifier>
> >                     <args>-Xmx512m</args>
> >                    
> > <removeDefaultWebapps>false</removeDefaultWebapps>
> >                 </configuration>
> >             </plugin>
> >         </plugins>
> >     </build>
> > 
> > [2]
> > 
> >         try(final Connection connection =
> > dataSource.getConnection()){
> >             writer.println("Metadata at: " +
> > connection.getMetaData().getUserName());
> >             writer.println("Metadata at: " +
> > connection.getMetaData().getDriverName());
> >             writer.println("Metadata at: " +
> > connection.getMetaData().getDriverVersion());
> > 
> >             boolean valid = connection.isValid(1000);
> > 
> > [3]
> > 
> > curl http://localhost:8080/jdbc-servlet/
> > Metadata at: SA
> > Metadata at: HSQL Database Engine Driver
> > Metadata at: 2.7.1
> > 
> >  JDBC Connection is valid @ timestamp = 1685439527124
> > 
> > [4]
> > 
> > <Resource id="MSSQL_Database" type="javax.sql.DataSource">
> >     JdbcDriver com.microsoft.sqlserver.jdbc.SQLServerDriver
> >     JdbcUrl
> > jdbc:sqlserver://qa.company.local:1433;databaseName=myDatabase
> >     UserName username
> >     Password password
> >     JtaManaged true
> >     InitialSize 10
> >     MaxActive 128
> >     MaxIdle 25
> >     MinIdle 10
> >     AccessToUnderlyingConnectionAllowed true
> >     TestOnBorrow false
> >     TestWhileIdle true
> >     TimeBetweenEvictionRuns 1 minute
> >     MaxWaitTime 0 seconds
> >     PoolPreparedStatements true
> >     MaxOpenPreparedStatements 1024
> >     ValidationQuery select 1
> > </Resource>
> > 
> 
>

Reply via email to