I have created an Android App with the Android Studio IDE. I have done all the codes, everything seems to be ok, but I get error every time I try to send to SQL Server. I know I am very close to figuring it out, and I know it has something to do with the IP address. I have enabled all the Protocols for SQL Server.
I've disabled the Windows Firewall.
Anti-virus is not the issue.
I am very confused on which IP Address to use for communication to work properly. Both Computer and Tablet are connected to my iPhone Hotspot network.
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
String username = "sa";
String password = "patrickdorian";
String gender = "";
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection DbConn = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.137.166:1433/Android DB;"+"encrypt=false;user="+username+";password"+password);
[Here][1]
Here is the error when I try to send the data to SQL Server[1]: https://i.stack.imgur.com/G3hID.jpg
Related
I want to connect to my Azure DB from Android. From Android side im using JDBC:
Connection con = ConnectionJDBC.connectionClass();
String query = "SELECT * FROM mytable";
Statement stmt = con.createStatement();
stmt.executeUpdate(query);
From azure side, my server is normally up and running and the firewall settings allow IPs 0.0.0.0 to 255.255.255.255. Everything else is unchanged.
That also works for most WiFi networks over which I made the request. However, it doesn't work for my university's WiFi (specifically ETH Zurich), con will just be null. Does someone know what the problem could be? I think it lies in the configuration of the Azure Server but I don't know what else I could change.
Please see JDBC vs Web Service for Android, as suggested by Morrison Chang: JDBC should not be used and is sometimes blocked. Instead create a mobile app service in Azure (they will change the name to web app service), and connect to that server, as suggested here: https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-android-get-started
Hi I created a SQL management Database, I wish to connect to the Database through Android App
I am not what I did wrong, I am not able to login.
This my SQL management Studio 2012, My DataBase name I call it DB.
This is my SQL Server Configuration manager, what I did is I enable TCP/IP and shared memory.
And then I enable all the IP, and I set the ALL port to 1433, the dynamic port I leave it empty.
I create the database using this username
This is what my code is like for my Android Java file, connection to database
String driver = "net.sourceforge.jtds.jdbc.Driver";
String connString = "jdbc:jtds:sqlserver://127.0.0.1:1433/db;encrypt=false;
user=username;password=1234;instance=SQLEXPRESS;";
String username = "username";
String password = "1234";
int id;
Is it something wrong with my step, how come it is not connecting?
Connecting directly to a DB from android is highly discouraging. The primary reason is performance. See, it is really expensive to keep a remote connection alive than rather just call Web Services on demand which is more portable and also more secure.
Therefore, its better to develop a REST API instead for your service and invoke it from client android app or any other client for that matter.
Edit: For your current issue at hand, see if it works by replacing localhost IP to the real(assuming 192.168.0.16 is also ipa4 ip?) one.
String connString = "jdbc:jtds:sqlserver://192.168.0.16/db;encrypt=false;
user=username;password=1234;instance=SQLEXPRESS;";
I need to make a generic app which can be used by anyone.
App will connect directly to MS SQL server, which will be within intranet/wifi
I donot need to worry about security risk,
I donot want to use web service or anything which we need to do something on server.
I am new and I have tried every option but still can't connect to sql from android studio.
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
String url = "jdbc:jtds:sqlserver://192.168.0.7/MYDB;user=android;password=abcd;";
Connection DbConn = DriverManager.getConnection(url);
Please suggest the easiest way to connect, as I said it will be used by different people on different server
I need to connect directly with Dynamics NAV database without any middle tier
Can we connect directly to SQL Server from Android Studio?
Thanks for your comments
I found this and worked
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
I created and application which will sync data with local database on my server i achieve that my using jdbc codes . It is working fine on my Emulator.
Here is sample code which i'm using to connect to my database.. I'm using jtds.jdbc added jar file to access the local database.
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
Connection conn = DriverManager
.getConnection(
"jdbc:jtds:sqlserver://195.169.100.1:1433/dbname",
"username", "password");
Log.w("Connection", "open");
Statement stmtUserDetails = conn.createStatement();
//Fetching Data From Tbl
ResultSet resetUserDetails = stmtUserDetails
.executeQuery("select UserName,Password,Priviledges from TblmyTable");
When i'm trying to Connect Using Device in debugging mode. I'm Getting the Following Error on My LogCat
11-02 13:19:05.249: D/SntpClient(73): request time failed: java.net.SocketException: Address family not supported by protocol
Please Help me to Solve this issue.
dbname does not seem to be a valid socket.
Try fixing the jdbc connect-string
.getConnection( "jdbc:jtds:sqlserver://195.169.100.1:1433/dbname",
"username", "password");
update
the database connect you gave me in the comment
//192.165.100.3:1433/myTestDatabase", "aadi", "test123"
is not reachable from normal internet (i just tryed to open the database) and therefor not from the physical device. is there a firewall blocking the access?
I am trying to do ftp to local host. but im getting error
03-03 00:49:40.747: WARN/System.err(4151): java.net.ConnectException: /127.0.0.1:1160 - Connection refused
03-03 00:49:40.758: WARN/System.err(4151): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:255)
And the code follows like this
FTPClient ftp;
server = "10.0.2.2";
username = "newuser";
password = "wampp";
remote = "/sample.txt";
local = "/data/data/com.test.sample/files/sample/sample.txt";
ftp = new FTPClient();
InputStream input;
input = new FileInputStream(local);
ftp.storeFile(remote, input);
input.close();
I am using XAMPP server as my localhost. It Contains FileZilla. Same code works fine as normal java application.
It doesn't appear that you're actually using the server, username or password variables. Take a look at this example to get some direction:
http://hoang17.com/posts/android/android-how-to-upload-a-file-via-ftp
How is your android device connected to the network?? Can you even ping 10.0.2.2 from the device itself??
I suggest installing busybox on your android device, it has telnet and ftp commands to test your FTP server. If you cannot access your ftp from busybox/android shell, than you have firewall or port forwarding issues.