Java 7 SSL connection to SQL Server 2014 from Tomcat - java

I am trying to connect to SQL Server 2014 with Java 7 via JDBC driver and the error that the app throws is :
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server returned an incomplete response. The connection has been closed."
My code is:
driver ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
url ="jdbc:sqlserver://Ip:port;databasename=xxx";
user = "xxx";
pass = "xxx";
Class.forName(driver);
connection = DriverManager.getConnection(url, user, pass);
I downloaded the ODBC driver package from MSDN and have tried using each of the following in turn: sqljdbc.jar, sqljdbc4.jar, sqljdbc41.jar, and sqljdbc42.jar, but I got the same error each time.

I resolve the issue using JTDS as driver manager , my code now is :
driver ="net.sourceforge.jtds.jdbc.Driver;
url ="jdbc:jtds:sqlserver://Ip:port;databasename=xxx";
user = "xxx";
pass = "xxx";
Class.forName(driver);
connection = DriverManager.getConnection(url, user, pass);
and i added the lib jtds1.5.1 in my classpath.

Related

Java SQL Server connection string

How can i create a java connection to an sql server located on a different server and in a different location (remote).
I am new to SQL Server, the server holding the database is 172.16.18.145 and the machine where am running the application from is 192.168.17.5
Your JDBC url would include the server name and port. Could you please elaborate the problem you are facing
String url="jdbc:db2://172.16.18.145:50007/exampledb";
String user="db2inst1";
String password="password";
connection = DriverManager.getConnection(url, user, password);

Error while connecting to SQL database

I am getting the following error while connecting to the MS SQL 2008 R2 from a specific server, from other severs it works fine.
com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server returned an incomplete response. The connection has been closed.".
The following is my code to connect to the database:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(db_info, db_userid, db_password);

Unable to connect to sql server 2008 with jdbc

I'm trying to connect to a sql server with JDBC in java.
My server uses a windows authentication.
I use this code:
String url = "jdbc:sqlserver://MYPC\\MYSERVER;databaseName=MYDB;integratedSecurity=true";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url);
In my classpath i have the file:
jtds-1.3.1.jar and sqljdbc4.jar
And i have a VM argument:
-Djava.library.path="SQLPATH\jtds\x64\SSO"
When i run the code, i have this exception:
com.microsoft.sqlserver.jdbc.SQLServerException: Unable to connect to the host MYPC
Do you know what is wrong?
The URL syntax is jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
Did you try to ping your host using ping command ? Or try with IP address.
If //MYPC\\MYSERVER is a network path, I'd imagine it needs to look like this:
\\MYPC\\MYSERVER
Of course, if the SQL Server 2008 instance is setup as the default instance, the \\MYSERVER portion isn't necessary.

Connecting to Azure SQL DB via JTDS on an Android device

I'm using JTDS 1.2.7 to connect my Android app to a Windows Azure SQL Server.
Source code:
String connectionString =
"jdbc:jtds:sqlserver://SERVER.database.windows.net:1433;database=demo;" +
"user=test#SERVER;password=PASSWORD;ssl=require";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection con = DriverManager.getConnection(connectionString);
Statement st = con.createStatement();
res=st.executeQuery(sql);
When I try to connect to the database I get the
java.lang.NoClassDefError: com.sun.net.ssl.SSLContext
exception.
I tried to add jsse.jar to my build path, but the app just shuts down instead of making connection.
What am I doing wrong?

Connecting to external database using java

I have a java program that connects to a MS SQL database. The program works perfectly when running through eclipse however I get an error when I run it through AIX:
java.sql.SQLException: Network error IOException: A remote host refused an attempted connect operation.
I am using jtds to connect:
String connectionString = "jdbc:jtds:sqlserver://"+dropez_ip_address+"/"+dropez_db_name;
ResultSet rs = null;
Statement stmt = null;
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(connectionString, dropez_db_username, dropez_db_password);
stmt = conn.createStatement();
}catch(Exception e){}
From jTDS documentation:
Why do I get java.sql.SQLException: "Network error IOException: Connection refused: connect" when trying to get a connection?
The "Connection refused" exception is thrown by jTDS when it is unable to connect to the server. There may be a number of reasons why this could happen:
The server name is misspelled or the port number is incorrect.
SQL Server is not configured to use TCP/IP. Either enable TCP/IP from SQL Server's Network Utility app or have jTDS connect via named pipes (see the URL format for information on how to do this).
There is a firewall blocking port 1433 on the server.
To check whether TCP/IP is enabled and the port is not blocked you can use "telnet 1433". Until telnet doesn't connect, jTDS won't either. If you can't figure out why, ask your network administrator for help.
My bet is your firewall does not allow the AIX host to connect.

Categories