Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have android app and sql server database.
my question is how can i connect my android app to sql database Locally i don't want access database from server. i am using android studio and sql server 2005
thanks in advance

What I have tried:

public void ConnectToDatabase(){
try {

// SET CONNECTIONSTRING
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
String username = "XXXXXXXXX";
String password = "XXXXXX";
Connection DbConn = DriverManager.getConnection("jdbc:jtds:sqlserver://192.188.4.83:1433/DATABASE;user=" + username + ";password=" + password);

Log.w("Connection","open");
Statement stmt = DbConn.createStatement();
ResultSet reset = stmt.executeQuery(" select * from users ");


EditText num = (EditText) findViewById(R.id.displaymessage);
num.setText(reset.getString(1));

DbConn.close();

} catch (Exception e)
{
Log.w("Error connection","" + e.getMessage());
}
}
Posted
Updated 14-Jul-16 1:17am
Comments
Richard MacCutchan 14-Jul-16 6:45am    
"i don't want access database from server. i am using android studio and sql server 2005"
Do you see anything wrong with those two statements?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900