Ok good. So, to summarize: by default you can configure on SFSDBManager from the AdminTool which will be created for you at startup and you will be able to access it from the Extension itself.
In your case you will also need other SFSDBManagers to be able to talk to the other databases.
Final suggestion, you might also want to create your own thread pool for DB work if you plan to have concurrent queries running on those DBs.
The DBManager is NOT active in this Zone
Re: The DBManager is NOT active in this Zone
Groovy. Thanks!
Re: The DBManager is NOT active in this Zone
I know this is old but this was pretty relative to what I was experiencing. I know I am doing something wrong I just don't know what.
I followed https://smartfoxserver.com/blog/querying-the-database-and-sending-resultsets/ and http://tutorialtous.com/smartfoxserver/dbconfiguration.php#adminpanel
My client is a Unity Application.
I downloaded the server extensions source code for the People example and changed things slightly to
GetPeopleHandler.java
PeopleExtension.java
In my Unity client application I have logged an event listener to the "getPeople" response event that just writes the table to the console of the Unity Editor. The request is sent after I enter the lobby.
I then set things up in the zone configuration in the Admin Tool standalone the following are my settings
activate = true
driver class = com.mysql.jdbc.Driver
connection string = jdbc:mysql://127.0.0.1:3306/sfs2x
userName = root
password = ********
Test SQl = SELECT now()
max active = 10
max idle = 10
exhausted pool action = GROW
I then hit submit and reload. Then I restarted the server. Waited for it to start and ran the client application. After I connected and logged in the request fired but the database failed with this SQL exception:
{people}: SQL Failed: java.sql.SQLException: The DBManager is NOT active in this Zone. SQL Query failed. Please activate it the DBManager from the AdminTool
What did I do wrong here? I feel like I followed all the steps, I keep rereading the docs and tried searching up an answer but nothing really worked for me.
I followed https://smartfoxserver.com/blog/querying-the-database-and-sending-resultsets/ and http://tutorialtous.com/smartfoxserver/dbconfiguration.php#adminpanel
My client is a Unity Application.
I downloaded the server extensions source code for the People example and changed things slightly to
GetPeopleHandler.java
Code: Select all
package people;
import java.sql.SQLException;
import com.smartfoxserver.v2.db.IDBManager;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSArray;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;
public class GetPeopleHandler extends BaseClientRequestHandler
{
@Override
public void handleClientRequest(User sender, ISFSObject params)
{
IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
String sql = "SELECT * FROM people";
try
{
// Obtain a result set
ISFSArray res = dbManager.executeQuery(sql, new Object[] {}); // added the new Object[] parameter
// Populate the response parameters
ISFSObject response = new SFSObject();
response.putSFSArray("people", res);
// Send back to requester
send("getPeople", response, sender);
}
catch (SQLException e)
{
trace(ExtensionLogLevel.WARN, "SQL Failed: " + e.toString());
}
}
}
PeopleExtension.java
Code: Select all
package people;
import com.smartfoxserver.v2.db.IDBManager;
import com.smartfoxserver.v2.entities.Zone;
import com.smartfoxserver.v2.extensions.SFSExtension;
public class PeopleExtension extends SFSExtension
{
@Override
public void init()
{
// ---- Added ----
Zone zone = getParentZone();
IDBManager dbManager = zone.getDBManager();
dbManager.init(zone);
// -- End Added --
trace("People Example Started!");
addRequestHandler("getPeople", GetPeopleHandler.class);
}
@Override
public void destroy()
{
trace("People Example Stopped!");
super.destroy();
}
}
In my Unity client application I have logged an event listener to the "getPeople" response event that just writes the table to the console of the Unity Editor. The request is sent after I enter the lobby.
I then set things up in the zone configuration in the Admin Tool standalone the following are my settings
activate = true
driver class = com.mysql.jdbc.Driver
connection string = jdbc:mysql://127.0.0.1:3306/sfs2x
userName = root
password = ********
Test SQl = SELECT now()
max active = 10
max idle = 10
exhausted pool action = GROW
I then hit submit and reload. Then I restarted the server. Waited for it to start and ran the client application. After I connected and logged in the request fired but the database failed with this SQL exception:
{people}: SQL Failed: java.sql.SQLException: The DBManager is NOT active in this Zone. SQL Query failed. Please activate it the DBManager from the AdminTool
What did I do wrong here? I feel like I followed all the steps, I keep rereading the docs and tried searching up an answer but nothing really worked for me.
Re: The DBManager is NOT active in this Zone
I think I figured out my problem, the connector jar was was 5.1 (or something like that) and my database was using 8.0.22 Updating the jar file in the extensions/__lib__ stopped the bug for me.
Re: The DBManager is NOT active in this Zone
Thanks for the update
Who is online
Users browsing this forum: No registered users and 59 guests