2

I'm using the following coding to connect locally on my SQL database

String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString = "jdbc:jtds:sqlserver://127.0.0.1:1433/dbname";
conn = DriverManager.getConnection(connString,"user","pass");

When I'm running this application it gives me Network error. Failed to connect to 127.0...

My firewall is open for 1433 and SQL config TCP/IP is enabled. What else must I still do?

faester
  • 14,886
  • 5
  • 45
  • 56
user3215134
  • 41
  • 2
  • 5

2 Answers2

6

If you are referring to a localhost from your device than use the http://10.0.2.2:8080/ instead of the http://127.0.0.1/ or http://localhost/.

Because your Android emulator is running on a Virtual Machine(QEMU) and you can not connect to a server directly running on your PC.

And If you running your app from Physical android device then please use your network ip from your PC. for example http://198.10.12.21:80/....

Also make sure that your device and PC(from where you call localhost) within same Network

Chirag Ghori
  • 4,231
  • 2
  • 20
  • 35
  • I did test all the IP but still give me the same error. When I'm using the PC IP the application just quit. When I'm using the wrong IP it will tell me it is the wrong IP but the correct IP the application just stop – user3215134 Jan 20 '14 at 13:33
  • I'm using the default 1433 port and it is on the same network – user3215134 Jan 20 '14 at 13:44
  • @BlackTiger Both of addresses doesn't work for me! 10.0.2.2:8080 for emulator, 192.168.1.3 for physical device, even 10.0.2.2:80. And i don't get any response or error in Log. – Dr.jacky Jul 02 '14 at 10:28
0

I fix this error. I was working on jtds driver v1.3.1. When I'm using the older version it works. I'm using now v1.2.5

user3215134
  • 41
  • 2
  • 5