0

I am trying to connect Android studio app to SQL server (Heidi SQL) I have the jtds jars (jtds-1.2.7.jar) file inside the lib and added the dependency. It still doesnt read the data and show the result from the database and I have this error:

E/Error: net.sourceforge.jtds.jdbc.Driver enter image description here

These are my codes.

public class ConnectionHelper {

Connection con;
String uname, pass, ip, port, database;

@SuppressLint("NewApi")
public Connection connectionClass() {
    ip = "127.0.0.1";
    database = "eat";
    uname = "root";
    pass = "pass";

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    Connection connection = null;
    String ConnectionURL = null;

    try{
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
            ConnectionURL = "jdbc:jtds:mysqlserver://" + ip + "/" + database + ";user=" + uname +
                    ";password=" + pass +";";

        connection = DriverManager.getConnection(ConnectionURL);
    }
    catch (Exception ex){
        Log.e("Error" , ex.getMessage());
    }
    return connection;
} }
jarlh
  • 42,561
  • 8
  • 45
  • 63
JJjang
  • 11
  • 1

1 Answers1

0

Looks like you are getting rejected using port 54015. Is that the port the SQL Server is listening to for JDBC connections? If not, you may need to append the port# to ConnectionClass.ip i.e. 127.0.0.1:[port number goes here] aka 127.0.0.1:12345

Jonathan Cole
  • 191
  • 1
  • 4
  • 127.0.0.1 is the SQL DB IP and the port is 3306. Still having the same error but this time is E/Error: net.sourceforge.jtds.jdbc.Driver Disconnected from the target VM, address: 'localhost:63382', transport: 'socket' try{ Class.forName("net.sourceforge.jtds.jdbc.Driver"); ConnectionURL = "jdbc:jtds:sqlserver://" + ip + ":" + port +";" +"databasename=" + database + ";user=" + uname +";" + "password=" + pass +";" ; connection = DriverManager.getConnection(ConnectionURL); } – JJjang Feb 03 '22 at 01:03