I am new to Android, and I tried copying a code to study how to connect my SQL database with my app. However, I get this error
Network error IOException: failed to connect to /169.254.57.155 (port 1433) from /:: (port 45212): connect failed: ETIMEDOUT (Connection timed out)"
Here is my ConSQL.java file:
`
package com.example.connectsql_trial;
import android.annotation.SuppressLint;
import android.os.StrictMode;
import android.util.Log;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConSQL {
@SuppressLint("NewApi")
public static Connection conclass(){
String ip="169.254.57.155",port="1433",db="Trialdb1",username="sa",password="art121499";
StrictMode.ThreadPolicy a = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(a);
Connection con = null;
String ConnectURL = null;
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
ConnectURL = "jdbc:jtds:sqlserver://"+ip+";"+"databasename="+db+";user="+username+";password="+password+";";
con = DriverManager.getConnection(ConnectURL);
}
catch (SQLException se) {
Log.e("Error SQLException", se.getMessage());
Log.e("Error SQLException", String.valueOf(se.getErrorCode()));
}
catch (ClassNotFoundException e) {
Log.e("Error Class not found", e.getMessage());
}
catch(Exception e){
Log.e("Error is", e.getMessage());
}
return con;
}
}
`