Reputation: 725
I am trying to connect to the database on the remote MS SQL server, using the provided connection string
. The connection string is as follows:
data source=qsss.gar.de\SQL2012,3000;initial catalog=City;persist security info=True;user id=usr;password=usr##2009;
I understand I should have the suitable drivers, so I have downloaded the SQL Server drivers from microsoft.com/download/en/details.aspx?id=21599
, and added them to the build path of my project. Those are sqljdbc.jar
and sqljdbc4.jar
.
I am just using this test code to see if the connection is established.
public static void main(String[] args) throws Exception {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection connection = DriverManager.getConnection(
"qsss.gar.de\SQL2012,3000;initial catalog=City;persist security info=True;user id=usr;password=usr##2009;");
System.out.println("Connected!");
}
Doing so, I get an error: Java Runtime Environment (JRE) version 1.8 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
What am I doing wrong here?
Upvotes: 0
Views: 1271
Reputation: 11911
Do not add both jars to your classpath since they both contain the com.microsoft.sqlserver.jdbc.SQLServerDriver
-class and in your situation the program loads the one from sqljdbc.jar
. Remove sqljdbc.jar
from your classpath and only add sqljdbc4.jar
so your program will always load the correct driver-version.
Upvotes: 2