Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status 500 - Java Runtime Environment (JRE) version 1.7 is not supported by this driver

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.

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.

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");
like image 579
user1940862 Avatar asked Jan 01 '13 11:01

user1940862


2 Answers

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

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

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

Try to delete sqljdbc.jar from the Tomcat lib folder

like image 58
a_horse_with_no_name Avatar answered Oct 24 '22 15:10

a_horse_with_no_name


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

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

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

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

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();
        }
    }

}
like image 36
Mohamed Yusuff Avatar answered Oct 24 '22 17:10

Mohamed Yusuff