Skip to main content
gamedev.net
🔒 Locked

Database for Java?

Started by menyo 9 replies 5.2k views
Original Post
menyo
menyo

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.

Avalander
Avalander

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.

menyo
menyo

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.

Nik02
Nik02

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

Niko Suni
menyo
menyo

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

Nik02
Nik02

Okay, I misunderstood this:

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

Niko Suni
TheChubu
TheChubu

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 
menyo
menyo

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.

dmatter
dmatter

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.

Ghaelkloern
Ghaelkloern

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/

kop0113
kop0113

If your usage of the database is quite low and your server can do its own locking (i.e an exclusive lock of the whole database whilst saving some player stats), then I might recommend SQLite.

There are a few java bindings knocking around like: http://code.google.com/p/sqlite4java

SQLite is cool because it is very easy to migrate between servers and does not rely on sockets so your game server can access it directly (obviously this means you want the SQLite database on the same server).

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.