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

后端 未结 2 1961
梦毁少年i
梦毁少年i 2020-12-10 13:56

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<

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 14:32

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

提交回复
热议问题