Tutorials/howto jdbc login

From CubeiaWiki

Jump to: navigation, search


How To: Deploy Simple JDBC Login Service

There's a simple JDBC login service included in the API for reference. It can be deployed to handle login from a database. This is slightly different from building an ordinary service as the classes are allready loaded in the system, and all you need to do is basically to configure it.

Create the SAR

The only thing you need in the service archive (SAR) is the "service.xml" file describing the service as the it's actual classes are already loaded in the system.

  • Create a directory called "META-INF".
  • Create a file in the above directory called "service.xml".
  • Open the file and copy in the following:
<service auto-start="true" is-public="true">
    <description />
    <exported />
  • Save the file.
  • ZIP the "META-INF" directory as "jdbc-login.zip", and change the file extension from "zip" to "sar.

You should now have a file called "jdbc-login.sar" which should look like this:

 - META-INF/service.xml

Deploy this file to your Firebase installation (copy to "game/deploy").

Create Data Source

You will need a data source for your installation.

  • Create a file in the Firebase deployment directory ("game/deploy") called "jdbc-login-ds.xml".
  • Open the file and copy the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
  <entry key="url">[jdbc-url]</entry>
  <entry key="driver">[jdbc-driver]</entry>
  <entry key="user">[username]</entry>	
  <entry key="password">[password]</entry>
  • Edit the file as needed and save it.

You should now have a file in the "game/deply" directory which could look something like this for a MySQL database:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
  <entry key="url">jdbc:mysql://localhost:3306/users</entry>
  <entry key="driver">com.mysql.jdbc.Driver</entry>
  <entry key="user">databaseUser</entry>	
  <entry key="password">xxx</entry>

Configure the Service

Now you need to configure the service to look at the correct database tables.

  • Open the "conf/cluster.properties".
  • Copy/edit the following:
  • Edit the file to match your own database.

Please note that the "id" column should be of the integer SQL data type. Also note that "jdbc-login" matches our "jdbc-login-ds.xml" file, ie. it's the data source file name excluding the "-ds.xml" suffix.

Copy the Driver JAR

You need to copy the JAR containing your JDBC driver to "lib/common". This is because it needs to be loaded by the system class loader.

That's it! You can now start Firebase and login with user credentials as configured from your database. Good luck, and head over to the forums if you have any questions.

Personal tools