Jump to content

I'm trying to make an android app connection to a sql server database. The problem is I don't think I have the driver configured correctly cause every time I hit the submit button I get this error in the Log:

07-01 15:24:59.010 29438-29438/com.example.joell.jdatabaseconnect W/Error connection: No suitable driver

I got the latest driver off this sit.

https://sourceforge.net/projects/jtds/files/jtds/1.3.1/

I put just the jar file into libs in android studio and right clicked it and added it to dependencies. The jar file is currently called jtds.jar

 

 

Ignore the fact the database and server fields are left blank.

 

 

public class MainActivity extends AppCompatActivity {

    String driver = "jdbc:jtds";
    private String server = "";
    private String database = "";
    private String userName = "";
    private String password = "";




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        try {
            Class.forName("net.sourceforge.jtds.jbdc.Driver").newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

    public void SubmitOnClick(View v){

        TextView uName = (TextView) findViewById(R.id.txvUsername);
        userName = uName.getText().toString();

        EditText pass = (EditText) findViewById(R.id.editText);
        password = pass.getText().toString();


        try{
            Connection DbConn = DriverManager.getConnection(driver +":" + server + "/" + database + ";user=" + userName + ";password=" + password );
            Toast.makeText(MainActivity.this, "Connected!", Toast.LENGTH_SHORT).show();
        }catch (Exception e){
            Log.w("Error connection", "" + e.getMessage());
            Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_SHORT).show();
        }

    }

}

 

Link to comment
https://linustechtips.com/topic/619450-android-app-connect-to-sql-server/
Share on other sites

Link to post
Share on other sites

you really should have an online api for your app to interact with rather than directly connecting to the database.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×