I'm trying to connect my Android app to my local machine database MS SQL. This is my connection string:
jdbc:jtds:sqlserver://localhost:1433/DajSve;encrypt=false;user=root;password=null;instance=FALE//SQLEXPRESS;
And I got this error:
java.sql.SQLException: Network error IOException: failed to connect to localhost/127.0.0.1 (port 1433): connect failed: ECCONREFUSED (Connection refused)
I tried a lot of things. Changed a connection string a lot of times, enabled TCP/IP and set it to port 1433, also turned off firewall but nothing helped. I'm always getting the same SQL Exception. I'm using SQL Server 2016..
try {
Class.forName(className).newInstance();
connection = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/DajSve;encrypt=false;user=root;password=null;instance=FALE//SQLEXPRESS;");
System.out.print("Uspjesno spojeni na bazu");
Statement stmt = connection.createStatement();
ResultSet reset = stmt.executeQuery("select * from Korisnik");
if (!reset.isBeforeFirst() ) {
System.out.println("nema podataka");
}else{
System.out.println("ima podataka");
}
} catch (SQLException e) {
e.printStackTrace();
System.out.print("Greska pri spajanju na bazu");
} catch (ClassNotFoundException e){
System.out.print("Greska - klasa nije pronađena");
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
I know there is a lot of similar questions but none of the answers have helped