I want to access the database directly from my Application without any web services. I have used many time web Services and by hit URL get Data but How can I access server database directly?
Please Help me how can i do this?
- 6 years ago
You need a JDBC driver for Microsoft SQL Server.
Please try http://jtds.sourceforge.net[^]
You can do something like this
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()); } }
Hot Questions