Maven项目中的多个web.xml数据库连接

时间:2017-11-17 06:37:13

标签: java maven database-connection web.xml

我不是Java新手,但我最近学会了使用web.xml文件连接到数据库。

连接到我已经设置的mySql和同一个maven项目中的MSSql数据库会很方便。

我已经对这个话题进行了一些研究,并没有找到我想要的答案。

这个问题并没有什么帮助,但是如果你想告诉我如何做到这一点,我已经提供了我的web.xml作为代码库。

任何正确方向的帮助都将受到赞赏。

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

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1">

    <context-param>
        <param-name>db.driver.class</param-name>
        <param-value>com.mysql.jdbc.Driver</param-value>
    </context-param>
    <context-param>
        <param-name>db.url</param-name>
        <param-value>jdbc:mysql://localhost:3308/lib-1323</param-value>
    </context-param>
    <context-param>
        <param-name>db.username</param-name>
        <param-value>root</param-value>
    </context-param>
    <context-param>
        <param-name>db.password</param-name>
        <param-value>admin</param-value>
    </context-param>



    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

1 个答案:

答案 0 :(得分:0)

这可以做到。我会对Spring和hibernate做一些研究。

我找到了this article which may help

您需要在pom.xml中使用Microsoft SQL Dependency,以及正确的驱动程序。

希望这有帮助。

相关问题