【问题标题】:Unable to determine jdbc url from datasource; Could not get Connection for extracting meta-data无法从数据源确定 jdbc url;无法获取用于提取元数据的连接
【发布时间】:2019-01-31 15:02:01
【问题描述】:

我正在创建一个新的 springboot 应用程序并尝试与 Sql Server 连接。但无法获得连接,我一直在通过互联网尝试很多解决方案,但没有任何效果。

以下是我得到的例外:

2018-08-25 05:55:52 INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2018-08-25 05:56:23 ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host RRI2SQLPW14V, port 1433 has failed. Error: "Invalid argument: create. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

2018-08-25 05:56:23 WARN  o.s.b.a.orm.jpa.DatabaseLookup - Unable to determine jdbc url from datasource
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host RRI2SQLPW14V, port 1433 has failed. Error: "Invalid argument: create. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host RRI2SQLPW14V, port 1433 has failed. Error: "Invalid argument: create. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

下面是application.properties的配置:

spring.datasource.url=jdbc:sqlserver://RRI2SQLPW14V\\SQL12EEP1:1433
spring.datasource.username=xxxxx
spring.datasource.password=xxxxx
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect
spring.jpa.hibernate.ddl-auto = validate

下面是我的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.oss</groupId>
	<artifactId>OSSIncidentsAutomation</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<name>ProductionIncidentAutomation</name>
	<description>Automate the production incidents logging in ASM database</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.3.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-integration</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-mail</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>

		<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
		<dependency>
		    <groupId>com.microsoft.sqlserver</groupId>
		    <artifactId>mssql-jdbc</artifactId>
		    <version>7.0.0.jre8</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>


</project>

请查看并帮助我连接到 DB。我不确定我在这里做错了什么。

注意:数据库没有防火墙层。

【问题讨论】:

    标签: sql-server hibernate spring-boot


    【解决方案1】:

    似乎是您的 application.properties 文件中的一个问题。

    异常清楚地说:

    Unable to determine jdbc url from datasource
    

    以如下方式更改数据源 url 属性: spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=springbootdb

    来源:https://dzone.com/articles/configuring-spring-boot-for-microsoft-sql-server

    【讨论】:

    • 我试过 jdbc:sqlserver://RRI2SQLPW14V\\SQL12EEP1:1433;databaseName=ASM_OSS 但没用。
    • 我认为问题在于您的数据源 url 中的“\\”。而是使用数据库服务器的 ip 而不是字符串“RRI2SQLPW14V\\SQL12EEP1”。
    • 另外,我在另一个 spring 应用程序中使用了这个 url:jdbc.url=jdbc:microsoft:sqlserver://RRI2SQLPW14V\\SQL12EEP1:1433。它在那里工作正常。
    • 如我所见,异常说明:与主机 RRI2SQLPW14V、端口 1433 的 TCP/IP 连接失败。所以,我认为 spring 无法占用完整的数据库服务器 url:“RRI2SQLPW14V\\SQL12EEP1”。
    • 我发现了一些奇怪的东西,当我将运行时环境更改为不同的 JRE8 而不是 JDK1.8 时,错误消失了。:在日志中获取以下内容:osojLocalContainerEntityManagerFactoryBean - 为持久性单元构建 JPA 容器 EntityManagerFactory '默认'。那么,会不会是我的 JDK 有问题呢?
    【解决方案2】:

    你可以看到enter link description here: 或者使用下面的 URL,以防上面的 URL 不起作用:

    jdbc.url=jdbc:sqlserver://<hostname>;instanceName=<instance_name>;databaseName=<database_name>;
    

    【讨论】:

      猜你喜欢
      • 2013-04-13
      • 2019-04-21
      • 2017-03-09
      • 2019-09-04
      • 2018-08-10
      • 1970-01-01
      • 2018-12-25
      • 2017-08-12
      • 1970-01-01
      相关资源
      最近更新 更多