how to connect sql server using JTDS driver in Android
Getting error "ClassNotFoundException" while using JTDS on ANDROID to direct access SQLSERVER?
After 3 hours RND, for finding solution for the same above error. I didnt get there is no error in the code, also I have import "jtds-1.3.0" library properly continues debugging of code still getting same error again and again.
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
}
I tried alternative to, changing line
...... Class.forName("net.sourceforge.jtds.jdbc.Driver");
to
...... (new Driver()).getClass();
...... (new Driver())
when I tried all of these, I tought there might be a problem in jtds-1.3.0 library, and what I did, just download the old version jtds-1.2.5 and import it; and the issue resolved.
So, friends out there If you getting same error and tried different ways already, try this.
android - sql server - connection either null or no suitable driver found
@NiravMadariya, The JDBC connection string with jTDS shoule be jdbc:jtds:sqlserver://<server>:<port>/<database>
, please see the jTDS FAQ which includes URL format
and the reason for No suitable driver
exception.
Note, if you are using the JTDS JDBC driver for Auzre SQL DB, then you will need to add ssl=require
to the URL of the connection string as like this jdbc:jtds:sqlserver://<server>:<port>/<database>?ssl=require
.
Meanwhile, using Microsoft JDBC Driver for SQL Server is a recommend way for Azure SQL DB, please see https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-java-simple/.
Sql Database connect Using the JDBC Driver with android
Change the Dirver Name and before import the lib file jtds 1.3.0.jar file.and change below the code it will work fine.............
public List<String> dbConnect(String Host, String Port, String db_userid,
String db_password) {
List<String> Db_list = new ArrayList<String>();
try {
String ConnectionString = "jdbc:jtds:sqlserver://" + Host + ":"
+ Port;
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(ConnectionString,
db_userid, db_password);
System.out.println("connected");
Statement statement = conn.createStatement();
String queryString = "select name from sys.databases";
ResultSet rs = statement.executeQuery(queryString);
while (rs.next()) {
Db_list.add(rs.getString(1));
}
} catch (Exception e) {
Db_list.add("Error");
e.printStackTrace();
}
return Db_list;
}
Related Topics
How to Get Current Buildtype in Android Gradle Configuration
Executing Multiple Asynctask's Parallely
Checking a Checkbox in Listview Makes Other Random Checkboxes Checked Too
How to Stop Other Apps Playing Music from My Current Activity
Taking Screenshot Programmatically Doesnt Capture the Contents of Surfaceview
Android App Crashes with Sigabrt Signal 6 Only While Eclipse Debugging
If I Call Getmeasuredwidth() or Getwidth() for Layout in Onresume They Return 0
App Completely Restarting When Launched by Icon Press in Launcher
How to Get Bitmap from a Url in Android
Xiaomi Does Not Receive Notification When Application Is Not Running
Android Picasso Library, How to Add Authentication Headers
Pick a Number and Name from Contacts List in Android App
Android - Gettargetfragment and Settargetfragment - What Are They Used For
Change Text Color of Selected Item in Spinner
How to Test If a Fragment View Is Visible to the User
Unsigned APK Can Not Be Installed
Why Does Gradle Build My Module in Release Mode When the App Is in Debug
Programmatically Enter Secret Code Like *#*#4636#*#* on Android