Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jboss 7 AS datasource for sqlserver

I run jboss in standalone mode and have set my datasource in the standalone.xml to the following:

<datasource jndi-name="MyDenaliDS" pool-name="MyDenaliDs_Pool" enabled="true" jta="true" 
                                                   use-java-context="true" use-ccm="true">
    <connection-url>
        jdbc:sqlserver://myip:1433;databaseName=mydb;integratedSecurity=true
    </connection-url>
    <driver>
        sqljdbc
    </driver>
    <security>
        <user-name>
            username
        </user-name>
        <password>
            password
        </password>
    </security>
</datasource>
<drivers>
    <driver name="sqljdbc" module="com.microsoft.sqlserver.jdbc">
        <driver-class>
            com.microsoft.sqlserver.jdbc.SQLServerDataSource
        </driver-class>
    </driver>                    
</drivers>

in the folder %jbosshome%\modules\com\microsoft\sqlserver\jdbc\ I have the sqljdb4.jar and the following module.xml:

<?xml version="1.0" encoding="UTF-8"?>
<module name="com.microsoft.sqlserver.jdbc" xmlns="urn:jboss:module:1.0">
    <resources>
        <resource-root path="sqljdbc4.jar"/> 
     </resources>
     <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/> 
     </dependencies>
</module>

When I start the jboss it gives me the following error:

> New missing/unsatisfied dependencies:    service
> jboss.jdbc-driver.sqljdbc (missing)

Anyone know what I've done incorrect or what I'm missing?

like image 416
Marthin Avatar asked Dec 06 '11 13:12

Marthin


People also ask

Can JDBC connect to SQL Server?

Microsoft provides a JDBC driver for use with SQL Server and Azure SQL Database, enabling connectivity from any Java application, server, or applet.


2 Answers

With Jboss 7.1.1 I managed to get it working without specifying module.

Just put sqljdbc4.jar into deployment directory: %JBOSSHOME%\standalone\deployments

Configuration needed for datasource in standalone.xml is as follows:

<datasource jndi-name="java:jboss/datasources/myPool" pool-name="myPool" enabled="true" use-java-context="true">
    <connection-url>jdbc:sqlserver://127.0.0.1:1433;databaseName=myName;</connection-url>
    <driver>sqljdbc4.jar</driver>
    <pool>
        <min-pool-size>10</min-pool-size>
        <max-pool-size>100</max-pool-size>
        <prefill>true</prefill>
    </pool>
    <security>
        <user-name>myUser</user-name>
        <password>myPassword</password>
    </security>
    <statement>
        <prepared-statement-cache-size>32</prepared-statement-cache-size>
        <share-prepared-statements>true</share-prepared-statements>
    </statement>
</datasource>
like image 39
JJ Roman Avatar answered Sep 21 '22 14:09

JJ Roman


using Jboss AS 7.1.1, as well as putting the module in %jbosshome%\modules\com\microsoft\sqlserver\jdbc\main I had to make a slight change to the xml - the driver element in standalone.xml should be :

 <driver name="sqljdbc" module="com.microsoft.sqlserver.jdbc">
      <driver-class>
           com.microsoft.sqlserver.jdbc.SQLServerDriver
      </driver-class>
 </driver>

and the module.xml should be:

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="com.microsoft.sqlserver.jdbc">

    <resources>
        <resource-root path="sqljdbc4.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>

</module>
like image 164
blank Avatar answered Sep 21 '22 14:09

blank