Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is it possible to act as a MySQL server in a Java or Android application, such that applications like HeidiSQL can connect to it?

What I want to do is to write an application for Android which behaves as a MySQL server for an arbitrary database on that device. Since there are many MySQL clients that can connect to MySQL servers, it would be ideal if I could mimic such a server.

As it currently stands, I have three options:

  • Use some sort of MySQL server library (if that exists);
  • Write the server myself, including implementing the (trivial/needed parts of the) protocol (is this feasible?);
  • Drop the MySQL server approach altogether and write a specific client/server myself.

In the end, the server (Android application) should be able to process and respond to simple queries a client sends to it.

Which options are feasible, and best suitable?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Sit down and write the client/server properly yourself.

If you are not willing to implement all of the protocol, just doing part of it can leave you with significant and strange breakages when some application tries to:

  • prepare a statement
  • iterate over a result set
  • do a transaction (and a rollback!)
    • do something 'at the same time' as another thing (can you do a update foo set bar = bar + 1 without getting into an infinite loop?)
  • do nested statements (example:

    SELECT  PLAYERS.PLAYERNO, NAME,
       (SELECT   COUNT(*)
        FROM     PENALTIES
        WHERE    PLAYERS.PLAYERNO =
                 PENALTIES.PLAYERNO) AS NUMBER_OF_PENALTIES,
       (SELECT   COUNT(*)
        FROM     TEAMS
        WHERE    PLAYERS.PLAYERNO =
                 TEAMS.PLAYERNO) AS NUMBER_OF_TEAMS
    FROM    PLAYERS
    

This isn't just for trying to present the "I'm a MySQL server to the world" but just "I'm an SQL server to the world"...

There are simpler things than a MySQL server. You could go for just "I'm a database" and use ODBC to connect to it rather than trying to mirror MySQL. Or something like GNOME-DB.

All of this, however, presupposes that the data that you have behind this interface is actually relational and can be queried in a relational manner. If it isn't you may be finding yourself with the object-relational impedance mismatch in reverse (and then back again?).

Thus, returning back to my original suggestion. Write the client and server in accordance with the data that you have modeled behind it. Trying to write something that matches the appearance of a database is going to involve nearly writing a database... and that is no little task.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.