View Full Version : [Solved] How to run DatabaseWithJDBI Example
04-20-2011, 01:32 PM
I have problems running the DatabaseWithJDBI Code Example , If any one able to run it please help me as soon as you can
what I want to do is to make Database Example but running in unity3d so if any one did that before I will be thankful
Thanks in Advance
04-20-2011, 02:12 PM
From the information posted in your other thread, you will be better off starting with a currently unreleased example. I'm pretty sure that this example works with ES5.1 - please let me know if you have problems with it.
Download the zip (http://www.electrotank.com/docs/es5/zips/DBLoginMySQL.zip).
Set up a MySQL database. If you use UserInfo as the name of the database it might be less confusing.
Unzip the zip. Look for server/java/config/database.properties and server/java/dist/ext/DBLoginMySQL/config/database.properties. Specify the url for MySQL, and your MySQL username and password, and save the file. The second is the one that you will drop into your ES5, the first is the one that will be deployed if you have to recompile the extension, so just edit one then copy to the second location.
Drop the entire server/java/dist/ext/DBLoginMySQL folder into the extensions folder of your ES5, so that you see server/extensions/DBLoginMySQL there. Restart your ES5. Use the ES Admin to create two server level components: DBLoginHandler and DatabasePlugin. After adding the two server level components, restart ES5 again.
There is Unity client for this example. Let me know if you have any other questions.
Note: Derby would work well here too, but this example was the closest match to your needs. It would be pretty easy to modify this example to use Derby instead of MySQL, or some other DBMS for that matter, if you decide you need a different DBMS.
04-21-2011, 02:57 AM
Thank you very much , I really appreciate your help :D
as I didn't work with MySQL from about 4 years , so i think I have to revise it to be able to run this example , but what I have understood till now that to get my work done I have to do somethings :
1- I have to write my own extension in java to be able to connect to SQL database
2- Install this extension to server
3- write my client application for unity using C# language
I hope that I'm on the right way now , and I hope I'm able to run the previous example
Thank you very much again
04-21-2011, 04:49 AM
That is correct. You should be able to start with the example that I provided. Look at DBLoginMySQL/server/java/config/sql/ for SQL scripts. If you edit CreateUserTable.sql to include the fields that you will need, and do not have that table in your database, ES5 will create the table when the extension starts up. Note: going by memory on that, because I implemented it several months ago.
04-26-2011, 03:03 PM
Thank you very much for your reply :D
I have downloaded the example and install MySql and create database UserInfo and add the data (username , password , 0) to users tables
then I have edited the database.properties file and add the username and password the same as the user that I have added to database
then I have installed the extension and add two server component then restart the server , but when I run the unity client example I got the error Login Failed message with Database Error
so I don't know what is the wrong that I have did , so could you please help me out , because I relly need to run this example as soon as I can
Thanks in Advance
04-26-2011, 03:17 PM
database.properties needs the MySQL username and password. That is, the username and password that you use when you use MySQL manually. This is what ES5 will use to log on to MySQL. The UserInfo table needs the usernames and passwords of your various ES5 users, and the way that the example is set up, this will auto-populate. That is, if a user tries to log in, and that username isn't found in the UserInfo table of the database, the username and password from the LoginRequest will be inserted into the table, with a rank of 0. The rank field is there so that the example can demonstrate how to update a field in the database, outside the login process.
If that doesn't do the trick for you, check the server logs, both ElectroServer5.log and Console.log, and give me any error messages that you see. It's also possible that you will need a patched version of ES5 for this example to work. It's been several months since ES5.1 was released, and a couple of months since I wrote that example, so I can't remember if there were changes needed to ES5 to get it to work.
04-26-2011, 04:00 PM
Thank you very much , it's works , Thank you again for your help
04-26-2011, 04:03 PM
Hooray! Let me know if you run into any other problems with it.
04-26-2011, 04:16 PM
My next task is to write the extension to connect SQL database with Unity , I hope I can do that , and If I successfully did this task I will be happy to share it with you , Thanks in Advance
04-26-2011, 04:22 PM
You don't connect directly to the database from the Unity client. You use a Unity client to send a plugin request, and the plugin then does the database query or insert or update. See the way that the example gets the current rank, and updates it, and the way that the managed object Controller persists the changes.
04-27-2011, 03:04 PM
Yes, I have understood that I have to write my own plugin that will connect to database and perform the CRUD operations and then install those plugins on the electroserver , then my unity client can connect to Database through electrotank server
but when I opened the source of the Example that you have sent it to me (DBLoginMySQL) , I have notice that you are using a lot of jar files that isn't included in the Electroserver server lib folder like (bcpg-jdk16-141 , commons-dbcp-1.2.2 , commons-pool-1.4 , jdbi-2.2.1 , mysql-connector-java-5.0.4-bin) , so my question now is what is the usage of those libraries? and if I can use them to connect to SQL Database? and If I need to rewrite some libraries to do so ?
I hope that you have the time to answer my question as soon as possible
Thanks in Advance
04-27-2011, 03:14 PM
You just drop those 3rd party jar files into your own project. If you aren't using MySQL, then you don't need the mysql one, but you would need a jar that is the database driver for whatever SQL you use. The commons ones are Apache Commons utilities of various types. The jdbi one is for JDBI, which is what that example uses for the database connection - it's more secure than standard JDBC because you can bind the parameters, which minimizes the risk of SQL injection attacks.
04-28-2011, 01:26 PM
Thank you very much for your help , I'm trying to understand the source code of the server side extension to be able to modify it to work with SQL database , and I have downloaded the JDBC driver for SQL instead of MySql JDBC driver , but is there any tutorial that can help me understand the example code quickly , I feel that I'm missing inside the code :D
Thanks in Advance
04-28-2011, 01:40 PM
We don't have any explanation of how the various parts of the database examples work. If you have a question about how to modify the example to do something else or how some specific part works, just ask here. You are working off DBLoginMySQL, right? Edit Controller.java to add a new public method for interacting with the database. If you aren't familiar with JDBI, see the JDBI javadocs. (http://jdbi.codehaus.org/apidocs/index.html) Any plugin in the same extension can use public methods in Controller (the way that DatabasePlugin does) or DatabasePlugin (using getApi().getServerPlugin). Any plugin that is not in the same extension can use the DatabasePlugin.interop method. Clients can send requests to the DatabasePlugin too.
05-02-2011, 10:22 AM
Thank you very much , I have a problem now , when I run the example on JDK 6 and Netbeans 7 , I have no errors and it compile and build successfully , but because that netbeans 7 does not have plugin for UML modeling tool and I need to use UML Modeling tool to understand the relation between classes so I'm now using JDK 5 with netbeans 6 and I have some errors like
(....\server\DBLoginMySQL\src\com\electrotank\elec troserver5\examples\dblogin\Controller.java:50: method does not override a method from its superclass)
so what is the problem now ?
Thanks in Advance
05-02-2011, 12:46 PM
When I developed DBLoginMySQL, I had the source level set to JDK 1.5, but the platform level to JDK 1.6, and used NetBeans 6.1. ES5 requires JVM 1.6+ to run the server.
Can you try changing the platform to JDK 1.6?
05-03-2011, 10:19 AM
Thank you very much for your reply , i just has another question , how can I test the functionality of the class library of the extension before install it in the server , should I make another project and add the jar file of class library to it and write the main function or what , I have did that before but it doesn't work with me , Sorry my question seems to be very stupid , but really I need some help here
Thanks in Advance
05-03-2011, 11:32 AM
While it's possible to test parts of an extension using JUnit tests, I almost never bother because so much of the time the bugs that I have to chase are due to the client-server communications. Any functionality that requires your extension to use getApi() methods won't work, because the api object is injected by ES5 (so your extension doesn't instantiate it).
Most developers have two or three ES5s, such as one for development, one for QA, and one for production. See Debugging Extensions (http://www.electrotank.com/docs/es5/manual/debugging_extensions.htm) for some tips.
Powered by vBulletin® Version 4.1.6 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.