有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法通过Apache Tomcat连接到MSSQL数据库

我正在尝试设置Geoportal 1.2.7,在Apache Tomcat 8.5.6MSSQL Server 2012, JDK 8, and jdbc 4上运行。我可以登录Geoportal,但当我进入“管理”选项卡时,会出现错误

"A database communication error has occurred"

检查Apache日志文件,我发现有一个严重错误

java.sql.SQLException: Cannot create PoolableConnectionFactory (The port number 1433:geoportal is not valid.)

我在jdbc的配置中尝试了一系列不同的条目,但它总是返回到那个错误

<Context docBase="geoportal" path="/geoportal" debug="0" reloadable="true" crossContext="true">
    <Resources
         cachingAllowed="true"
         cacheMaxSize="100000"
     />
    <Resource name="jdbc/gpt" auth="Container" type="javax.sql.DataSource"
              driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
              url="jdbc:sqlserver://SQLDEMOSERVER:1433:geoportal"
              user="******"
              password="*******"  
              maxTotal="20"
              maxIdle="10"
              maxWaitMillis="-1" />
</Context>

这只是我最近的一次尝试。我在网上看到过关于url应该是什么样子的相互矛盾的帖子

我试过url="jdbc:sqlserver://SQLDEMOSERVER:1433;databaseName=geoportal" (Geoportal won't launch), url="jdbc:sqlserver://SQLDEMOSERVER:1433/databaseName=geoportal" (Then I get the port error), url="jdbc:sqlserver://SQLDEMOSERVER:1433" (Geoportal won't load).

我束手无策。我仔细检查了其余的配置文件,其中的编辑非常少,可能没有处理错误

如果有人能指出我的错误,我们将不胜感激


共 (2) 个答案

  1. # 1 楼答案

    这些URL在SQL Server 2012上适用于我:

    jdbc:sqlserver://localhost:1433;databaseName=test
    jdbc:sqlserver://localhost:1433;database=test
    

    这在SQL Server 2012中不适用,但可能适用于旧版本:

    jdbc:sqlserver://localhost:1433/test
    

    这些根本不起作用:

    jdbc:sqlserver://localhost:1433/databaseName=test
    jdbc:sqlserver://localhost:1433:test
    

    我想问题在别处(更详细地调查“不会启动”的问题)

  2. # 2 楼答案

    试试看

    url="jdbc:sqlserver://SQLDEMOSERVER:1433/geoportal