This post illustrate one of the problem which I faced while developing application for Android. The issue was very weird while I first got, since the same code works fine with normal Java applications.
I got the same issue with my Android test project too. This issue you will get if you use sqljdbc-1.2.0 is this
com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: Socket closed.
I tried googling for the issue and came to know with a bug with Microsoft
sqljdbc-1.2.0.jar.
You can find more information from here
http://blogs.msdn.com/b/jdbcteam/archive/2007/04/24/welcome-to-the-sql-server-jdbc-blog.aspx?PageIndex=5
Solution
Well, the solution is, use
jtds-1.2.7 which you can download from
here
Note
Don’t use the latest version of JTDS (jtds-1.3.1), since that too has bug with Android and this will again give you a ClassNotfoundException
I know this sounds a simple post, but it took
5 hours of my time to sort out both the above issue I faced.
I hope you find this solution useful.
Thanks,
Karthik KK
I tried jtds-1.2.7 and everything works fine. I can able to login to SQL server and execute stored procedure via queries.
I tried in Android 2.3.3, i.e, Gingerbird. But when I run the app in KitKat version, then app running fine but some anonymous exception with sql query.
I mean, I can able to login to the SQL sever with following statements:
Class.forName(“net.sourceforge.jtds.jdbc.Driver”);
GlobalClass.dbConnection = DriverManager.getConnection(..etc..);
But when I tried to execute a query, for example:
String query = “exec [procUserDtls] @DMLType=N’AL’,@inUserID='” + userName + “‘,@inPass_word='”+passW+”‘”;
PreparedStatement ps = GlobalClass.dbConnection.prepareStatement(query);
ResultSet result = ps.executeQuery();
I get anonymous exception on Android KitKat version. But the above query works fine in Gingerbird version.
What might be the reason?
Please help.
Regards
Partha Sarathi Mishra
I am not pretty sure about the exception that you are getting, but I faced the same problem in Kitkat and tried to execute and that worked fine. But did you tried with 1.3.1 ?
Thanks,
Karthik KK