HTTP状态500 - Java运行时环境(JRE)版本1.7不受此驱动程序支持

时间:2021-01-29 17:07:48

I am trying to access MS SQL server 2005 from a servlet file. I am using JDBC 4.0 driver. I have already added the JAR files sqljdbc.jar and sqljdbc4.jar files to my Tomcat /lib folder.

我正在尝试从一个servlet文件访问MS SQL server 2005。我使用的是4.0驱动JDBC。我已经添加了JAR文件sqljdbc。jar和sqljdbc4。jar文件到我的Tomcat /lib文件夹。

But while running code I am getting an error

但是在运行代码时,我得到了一个错误

HTTP Status 500 - Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.

HTTP状态500 - Java运行时环境(JRE)版本1.7不受此驱动程序支持。使用sqljdbc4。jar类库,它支持JDBC 4.0。

How is this caused and how can I solve it?

这是怎么引起的,我怎么解决呢?

My code is:

我的代码是:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = conn =   DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=school;user=sa;password=123");
PrintWriter pwOut = res.getWriter();
pwOut.println("Connected");
Statement st = conn.createStatement();
String searchCriteria = req.getParameter("txtSearch");
ResultSet rs = st.executeQuery("select * from student");
res.setContentType("text/html");

2 个解决方案

#1


23  

The error message is pretty clear. Tomcat is using the wrong driver.

错误信息非常清晰。Tomcat使用了错误的驱动程序。

You state that you copied sqljdbc.jar and sqljdbc4.jar into the Tomcat lib folder. That is most probably the reason for your problem.

您声明您复制了sqljdbc。jar和sqljdbc4。jar文件到Tomcat lib文件夹中。那很可能是你问题的原因。

You only need sqljdbc4.jar otherwise Tomcat picks up the wrong one.

你只需要sqljdbc4。否则,Tomcat会选择错误的jar。

Try to delete sqljdbc.jar from the Tomcat lib folder

试着删除sqljdbc。来自Tomcat lib文件夹的jar

#2


1  

Here is my Code to connect java to Microsoft sql Server 2012

下面是我将java连接到Microsoft sql Server 2012的代码

You only need sqljdbc4.jar that avail on offical Microsoft website. Here is the link:

你只需要sqljdbc4。这在官方的微软网站上是有用的。这是链接:

http://download.microsoft.com/download/0/2/A/02AAE597-3865-456C-AE7F-613F99F850A8/sqljdbc_4.0.2206.100_enu.exe

http://download.microsoft.com/download/0/2/a/02aae597 - 3865 - 456 - 613 - f99f850a8/sqljdbc_4.0.2206.100_enu.exe c - ae7f

It contains 2 jar files, and I am trying to use sqljdbc4.jar. This is the code I am using to connect:

它包含两个jar文件,我正在尝试使用sqljdbc4.jar。这是我用来连接的代码:

package com.Sql.ConnectDB;

import java.sql.*;
public class DbClass {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try{
            **String url="jdbc:sqlserver://localhost;databaseName=Student";**//important
            String user="username";
            String pass="password";
            **Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");**//important
            Connection con=DriverManager.getConnection(url,user,pass);
            System.out.println("Conneccted Successfully");
        }catch(Exception e){
            e.printStackTrace();
        }
    }

}

#1


23  

The error message is pretty clear. Tomcat is using the wrong driver.

错误信息非常清晰。Tomcat使用了错误的驱动程序。

You state that you copied sqljdbc.jar and sqljdbc4.jar into the Tomcat lib folder. That is most probably the reason for your problem.

您声明您复制了sqljdbc。jar和sqljdbc4。jar文件到Tomcat lib文件夹中。那很可能是你问题的原因。

You only need sqljdbc4.jar otherwise Tomcat picks up the wrong one.

你只需要sqljdbc4。否则,Tomcat会选择错误的jar。

Try to delete sqljdbc.jar from the Tomcat lib folder

试着删除sqljdbc。来自Tomcat lib文件夹的jar

#2


1  

Here is my Code to connect java to Microsoft sql Server 2012

下面是我将java连接到Microsoft sql Server 2012的代码

You only need sqljdbc4.jar that avail on offical Microsoft website. Here is the link:

你只需要sqljdbc4。这在官方的微软网站上是有用的。这是链接:

http://download.microsoft.com/download/0/2/A/02AAE597-3865-456C-AE7F-613F99F850A8/sqljdbc_4.0.2206.100_enu.exe

http://download.microsoft.com/download/0/2/a/02aae597 - 3865 - 456 - 613 - f99f850a8/sqljdbc_4.0.2206.100_enu.exe c - ae7f

It contains 2 jar files, and I am trying to use sqljdbc4.jar. This is the code I am using to connect:

它包含两个jar文件,我正在尝试使用sqljdbc4.jar。这是我用来连接的代码:

package com.Sql.ConnectDB;

import java.sql.*;
public class DbClass {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try{
            **String url="jdbc:sqlserver://localhost;databaseName=Student";**//important
            String user="username";
            String pass="password";
            **Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");**//important
            Connection con=DriverManager.getConnection(url,user,pass);
            System.out.println("Conneccted Successfully");
        }catch(Exception e){
            e.printStackTrace();
        }
    }

}