使用Java Web App连接到SQL Server时出现问题 [英] Issue connecting to sql server with java web app

查看:208
本文介绍了使用Java Web App连接到SQL Server时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到Azure上的sql server db的Java应用程序,当我在本地运行该应用程序时,我没有任何连接问题.但是,当我将应用程序部署到运行tomcat的Azure Web应用程序时,出现以下错误:

I have a java application that connects to a sql server db on Azure, when I run the application locally I have no issues connecting. However when I deploy my application to Azure web app running tomcat I get the following error:

java.sql.SQLException:未找到适用于jdbc:sqlserver://
的驱动程序

java.sql.SQLException: No suitable driver found for jdbc:sqlserver://

在我的pom.xml文件中

	<dependency>
		<groupId>com.microsoft.sqlserver</groupId>
		<artifactId>mssql-jdbc</artifactId>
		<version>7.0.0.jre10</version>
	</dependency>

我可以在web-inf/lib文件夹下看到sqlserver jar文件,这是创建连接的Java代码:

And I can see the sqlserver jar file under web-inf/lib folder, and here is the java code creating the connection:

String url = String.format("jdbc:sqlserver://%s:1433;database=%s;user=%s;password=%s;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;", hostName, dbName, user, password);
            connection = DriverManager.getConnection(url);
           

推荐答案

If you haven’t tried the following steps already, kindly perform the below suggestions and let us know if that makes any difference:

  1. 从您的app/lib文件夹中删除sqljdbc * .jar文件.
  2. 如果您使用的是自定义Tomcat或Azure Marketplace Tomcat Web服务器,请将此.jar文件复制到Tomcat
  3. 如果您要通过Azure门户启用Java(请选择 Java 1.8 Tomcat服务器),将sqljdbc.* jar文件复制到 与您的应用程序平行.然后,将以下类路径设置添加到web.config文件:
  1. Remove the sqljdbc*.jar file from your app/lib folder.
  2. If you are using the custom Tomcat or Azure Marketplace Tomcat web server, copy this .jar file to the Tomcat lib folder.
  3. If you are enabling Java from the Azure portal (select Java 1.8 > Tomcat server), copy the sqljdbc.* jar file in the folder that's parallel to your app. Then, add the following classpath setting to the web.config file:

< httpPlatform>
< environmentVariables>
< environmentVariablename ="JAVA_OPTS";值=" -Djava.net.preferIPv4Stack = true
-Xms128M -classpath%CLASSPATH%; [sqljdbc * .jarfile的路径] />
</environmentVariables>
</httpPlatform>

<httpPlatform>
<environmentVariables>
<environmentVariablename ="JAVA_OPTS" value=" -Djava.net.preferIPv4Stack=true
-Xms128M -classpath %CLASSPATH%;[Path to the sqljdbc*.jarfile]" />
</environmentVariables>
</httpPlatform>


这篇关于使用Java Web App连接到SQL Server时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆