MetaColon
MetaColon

Reputation: 2871

Jetty with SQL Server 2017 datasource

I have a local MS SQL Server 2017 (14.0.3006), which I want to use in my Hibernate application, that I host via Jetty. I had the same application running with Oracle (which worked well) and am now trying to use MS SQL instead. Therefore I have the following configuration in my jetty-env.xml (I also tried quite a few variations, e.g. that one, but they all produced the same error):

<Arg>
  <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
    <Set name="User">user</Set>
    <Set name="Password">password</Set>
    <Set name="DatabaseName">databaseName</Set>
    <Set name="ServerName">LOCAL_COMPUTER_NAME\SQLEXPRESS</Set>
    <Set name="PortNumber">1433</Set>
  </New>
</Arg>

In my pom.xml I have the corresponding dependency:

<dependency>
  <groupId>net.sourceforge.jtds</groupId>
  <artifactId>jtds</artifactId>
  <version>1.3.1</version>
</dependency>

This leads to the following error:

Failure: net.sourceforge.jtds.jdbcx.JtdsDataSource

With a warning showing up above in the log:

[WARNING] Config error at <New id="mydb" class="org.eclipse.jetty.plus.jndi.Resource"><Arg/><Arg>jdbc/mydb</Arg><Arg>
      <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource"><Set name="User">user</Set><Set name="Password">password</Set><Set name="DatabaseName">databaseName</Set><Set name="ServerName">LOCAL_COMPUTER_NAME\SQLEXPRESS</Set><Set name="PortNumber">1433</Set></New>
    </Arg></New>

What am I doing wrong?


This is the (simplified) content of my jetty-env.xml:

<?xml version="1.0"  encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="oracledb" class="org.eclipse.jetty.webapp.WebAppContext">

  <New id="mydb" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jdbc/db</Arg>
    <Arg>
      <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
        <Set name="User">user</Set>
        <Set name="Password">password</Set>
        <Set name="DatabaseName">databaseName</Set>
        <Set name="ServerName">LOCAL_COMPUTER_NAME\SQLEXPRESS</Set>
        <Set name="PortNumber">1433</Set>
      </New>
    </Arg>
  </New>

  <New id="log4j.properties" class="org.eclipse.jetty.plus.jndi.EnvEntry">
    <Arg>log4j.properties</Arg>
    <Arg class="java.lang.String">C:/TMP/logs/conf/log4j.properties.xml</Arg>
  </New>
  <New id="servername" class="org.eclipse.jetty.plus.jndi.EnvEntry">
    <Arg>servername</Arg>
    <Arg class="java.lang.String">test123</Arg>
  </New>
</Configure>

I can't show the whole original jetty-env.xml, as it contains classified information. It's similar to to the stack trace:

[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 505 resources
[INFO] Copying 14 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ Application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 481 source files to C:\Path\Application\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Application ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Path\Application\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ Application ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Path\Application\target\test-classes
[INFO] 
[INFO] <<< jetty-maven-plugin:9.2.21.v20170120:run (default-cli) < test-compile @ Application <<<
[INFO] 
[INFO] 
[INFO] --- jetty-maven-plugin:9.2.21.v20170120:run (default-cli) @ Application ---
[INFO] Logging initialized @32640ms
[INFO] Configuring Jetty for project: Application
[INFO] Plugin classpath augmented with <scope>provided</scope> dependencies: [file:/C:/Users/User/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar, file:/C:/Users/User/.m2/repository/org/apache/tapestry/tapestry-javadoc/5.4.3/tapestry-javadoc-5.4.3.jar, file:/C:/Users/User/.m2/repository/com/oracle/jdbc/ojdbc7/12.1.0.2.0/ojdbc7-12.1.0.2.0.jar, file:/C:/Users/User/.m2/repository/com/db/websso-api/1.2.2/websso-api-1.2.2.jar]
[INFO] webAppSourceDirectory not set. Trying src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:\Path\Application\target\classes
[INFO] Configuring Jetty from xml configuration file = C:\Path\Application\target\classes\jetty-env.xml
[WARNING] Config error at <New id="mydb" class="org.eclipse.jetty.plus.jndi.Resource"><Arg/><Arg>jdbc/mydb</Arg><Arg>
      <New class="net.sourceforge.jtds.jdbcx.JtdsDataSource"><Set name="User">user</Set><Set name="Password">password</Set><Set name="DatabaseName">databaseName</Set><Set name="ServerName">LOCAL_COMPUTER_NAME\SQLEXPRESS</Set><Set name="PortNumber">1433</Set></New>
    </Arg></New>
[INFO] Jetty server exiting.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  30.290 s
[INFO] Finished at: 2020-01-20T14:58:44+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.jetty:jetty-maven-plugin:9.2.21.v20170120:run (default-cli) on project Application: Failure: net.sourceforge.jtds.jdbcx.JtdsDataSource -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Disconnected from the target VM, address: '127.0.0.1:49800', transport: 'socket'

Upvotes: 4

Views: 695

Answers (1)

MetaColon
MetaColon

Reputation: 2871

I solved it by using

<Arg>
  <New class="org.apache.commons.dbcp2.BasicDataSource">
    <Set name="driverClassName">com.microsoft.sqlserver.jdbc.SQLServerDriver</Set>
    <Set name="url">jdbc:sqlserver://NUC-GWG190602\SQLEXPRESS;database=ECMS_DM;integratedSecurity=true</Set>
    <Set name="username">ECMS_DM</Set>
    <Set name="password">ecms_dm</Set>
  </New>
</Arg>

instead. I still don't know why it didn't work before, but at least it works now.

Upvotes: 4

Related Questions