Advertisement

Database for Java?

Started by September 29, 2014 03:01 PM
9 comments, last by kop0113 10 years, 3 months ago

Hi,

I am building a client/server based android game with LibGDX and Kryonet extension. The server will only be run in desktop mode, maybe i'll even setup the server completely loose from libGDX/android if that is possible with Kryonet. Anyway, i'm looking and weighing my options for a system to track player data, from login credentials to message logs and collections to player status.

Only the server side will communicate with the database directly. Kryonet supports http requests so i could setup a PHP script that communicates with the database and posts back data. But there must be a better more direct way I think. Is it possible to setup somekind of DB and sent/receive queries directly to/from the database.

- Plus points if this works with libgdx, since i have my server side working already in the LibGDX environment i would prefer to do it this way.

- I have a lot of experience with MySQL, so a SQL based solution is probably better. I don't know how much other DB's defer from SQL though.

Any input is welcome, if you think it would be common sense to just write binary data to disk to store stuff then say so. It is my first client/server game and i want to make it a success, just this storing of data gives me headaches.

Well, instead of a PHP script, you can communicate to the database with... Java DBC. As your server is already in Java, just implement the database access in Java instead of adding the additional overhead of calling a PHP api and so, it'll be easier and faster. Also, there are some libraries and frameworks to make your life easier (I'd recommend ActiveJDBC, but you can find some more through Google). Also, you can use MySQL or whatever database you prefer, so no problem with that.

I don't understand what do you mean by "LibGDX environment", but I don't think LibGDX has any integrated solution to access databases, but probably someone developed a third party solution, so it's worth to check.

Advertisement

Well, currently my server runs in a LibGDX framework/environment. I will just use the exe/jar from the desktop project to run the server so I do not expect to run into problems. But since there is no need to run the server from a android device I could probably ditch LibGDX and just use Java with Kryonet and add a DB extension to the mix to keep the server project clean.

For security reasons, you don't want to allow your clients to access the database directly.

Niko Suni

That is why i do all the database communication through the server side.

Okay, I misunderstood this:

"Is it possible to setup somekind of DB and sent/receive queries directly to/from the database."

Niko Suni

Advertisement

To connect to a database from Java all you need is a JDBC driver, establish a connection, and you can issue SQL queries right away.

Pretty much all big databases out there (MySQL, PostgreSQL, Oracle Database, etc) have a JDBC driver.

You can follow this tutorial on how to use JDBC http://docs.oracle.com/javase/tutorial/jdbc/

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Okay, I misunderstood this:

"Is it possible to setup somekind of DB and sent/receive queries directly to/from the database."

Yeah, what i meant was without weaving in a php script through a http request. So directly, but from the server side.

If you want a lightweight SQL solution then JDBC is the way to go.

If you like JDBC but don't like how tedious it is to use then look at the Spring framework's JDBCTemplate module, which fits exactly that purpose.

If you want to move away from SQL and towards ORM (Object-relational mapping) then looks into JPA and/or Hibernate.

As for databases themselves, any will do, including MySQL if that's what you're comfortable with.

Maybe Cassandra would be a good choice in this context?

It seems that there will be much more writes than reads, and that's the kind of use case Cassandra was designed for.
Datastax driver for Java is pretty straight-forward, but there are also drivers for other languages: http://planetcassandra.org/client-drivers-tools/

This topic is closed to new replies.

Advertisement