D. Joe
D. Joe

Reputation: 81

Connecting android application to MySQL through SQL server express

I've been looking for a way to connect an Android application to a MySQL server. Tried different codes and asked many programmers. Didn't get anywhere. I'd be happy if anyone would be able to guide me on what codes I need to look for or what it is that's missing in the code I tried.

The application I got to make involves creating some sql tables. For instance, at the beggining it needs to veriffy login data given by a user against that data in one of those tables.

In addition to Android studio, I was guided to install and use SQL server express (nothing else).

I created a table through SQL server express 2008 R2, but the connection to the server didn't work. The codes I found always involved a password and a username for the connection. Is that mandatory? I didn't get a username for the connection when I installed the server. It involved getting an instance name and a password.

I found a code in which one can define a password and a usename:

    private Connection conn;

    public MySQLConnection() throws SQLException {

        System.out.println("At MySQLConnection()");

        String driverName = "com.mysql.jdbc.Driver";
        try {
            Class.forName(driverName);
            Properties props = new Properties();
            props.setProperty("user","fred");
            props.setProperty("password","secret");
            props.setProperty("ssl","true");

            String url = "jdbc:mysql://zivpc/workers?user=fred&password=secret&ssl=true";
            Connection conn = DriverManager.getConnection(url);
            this.conn = DriverManager.getConnection(url);

            System.out.println("connected");


        } catch (ClassNotFoundException e) {
            System.out.println(e);
        }

Trying to connect results in the following exception: CommunicationsException: Communications link failure

Tried finding what are the correct connection parameters are, but could find the ones that work.

Upvotes: 0

Views: 126

Answers (1)

Dinesh
Dinesh

Reputation: 988

If your database resides in a server, you could consider making a http wrapper which can talk to the database. The Http end point can be a bridge between your database and an external application(Your Android app in this case).

The Android App can hit these http end points for login or whatever use case you might want to have.

Upvotes: 1

Related Questions