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