Page 1 of 1

Connecting to MYSQL

Posted: 16 Aug 2010, 21:14
by Caesar
I am been trying to solve this problem for days. Here is my config code

Code: Select all

<DatabaseManager active="true">
<Driver>org.gjt.mm.mysql.Driver</Driver>
<ConnectionString>jdbc:mysql://localhost:80/files</ConnectionString>
<UserName>root</UserName>
<Password>root</Password>
<TestSQL><![CDATA[SELECT COUNT(*) FROM items]]></TestSQL>
<MaxActive>10</MaxActive>
<MaxIdle>10</MaxIdle>
<OnExhaustedPool>fail</OnExhaustedPool>
<BlockTime>5000</BlockTime>
</DatabaseManager>

server error:

Code: Select all

it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFoxServer.java:339)
	at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:607)
Problems in config file: The Test SQL statement failed! Please check your configuration.
it.gotoandplay.smartfoxserver.exceptions.ConfigurationException: The Test SQL statement failed! Please check your configuration.
	at it.gotoandplay.smartfoxserver.lib.ConfigReader.readZoneConfig(ConfigReader.java:199)
	at it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFoxServer.java:339)
	at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:607)

Errors found in configuration files.
Unable to start the server.


Shutting down server...
I use a Mac, and Xampp is my web server. I placed the MYSQL connecter in 'Applications/Utilities'. I recommend you include a detailed article in the documentations for Mac and Windows users.

Also does Smartfox support PHP?

Posted: 17 Aug 2010, 07:32
by Lapo
Application/Utilities is not the right place to put your database driver.

The location of the JRE lib/ext/ folder under MacOSX is explained on Apple's website:
http://developer.apple.com/mac/library/ ... a1170.html

Also... are you sure the DB is running on port 80? That's pretty weird.

Posted: 03 Sep 2010, 20:30
by Caesar
I looked on the Xampp forums and the port is 80. I have mysql-connector-java-5.1.13-bin.jar in Macintosh HD > Developer > SDKS > MacOSX10.5u.sdk > usr > lib > java Do I need to place the folder that mysql-connector-java-5.1.13-bin.jar came from anywhere particular? At the moment that folder is in my downloads folder.

Posted: 09 Sep 2010, 21:32
by Caesar
bump

Posted: 09 Sep 2010, 22:05
by Caesar

Code: Select all

<Zones>	
		
		<Zone name="Zone" emptyNames="false" uCountUpdate="true" buddyList="20" maxUsers="4000" customLogin="true">
		
               <DatabaseManager active="true">

	             <Driver>org.gjt.mm.mysql.Driver</Driver>
	             <ConnectionString>jdbc:mysql:/localhost/sunnytropical</ConnectionString>
	             <UserName>root</UserName>
                     <Password></Password>
	             <TestSQL><![CDATA[SELECT COUNT(*) FROM items]]></TestSQL>
	             <MaxActive>10</MaxActive>
	             <MaxIdle>10</MaxIdle>
	             <OnExhaustedPool>fail</OnExhaustedPool>
	             <BlockTime>5000</BlockTime>
                </DatabaseManager>
			<Rooms>
				<Room name="Room1" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true" />
				<Room name="Room2" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true" />
			</Rooms>
			<Extensions>
				<extension name="" className="" type="" />
			</Extensions>
         </Zone>
I have read and followed the directions in http://forums.smartfoxserver.com/viewtopic.php?t=2796
http://forums.smartfoxserver.com/viewtopic.php?t=7380
http://forums.smartfoxserver.com/viewtopic.php?p=30550

possible answer to the million dollar question

Posted: 11 Sep 2010, 09:09
by d3m0nlogic
I am not sure if it will work for you.. but here goes.

I use ubuntu, and when I read the docs it says that I DON"T have to use the config context for the driver ..since JDBC is already available to use with java.sql package

Example ::

import java.nio.channels.SocketChannel;
import java.util.LinkedList;
import java.util.Vector;

import it.gotoandplay.smartfoxserver.SmartFoxServer;
import it.gotoandplay.smartfoxserver.data.*;
import it.gotoandplay.smartfoxserver.extensions.AbstractExtension;
import it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension;
import it.gotoandplay.smartfoxserver.lib.ActionscriptObject;
import it.gotoandplay.smartfoxserver.events.*;

import org.json.*;
import java.sql.*;//*the class you need for mysql fun

public class FunRoom extends AbstractExtension implements ISmartFoxExtension
{

private static Zone _zone;
private static Room _room;


@Override
public void init()
{
_zone = SmartFoxServer.getInstance().getZone("FunFactory");

Connection con = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://x.x.x.x:3306/bingo?user=foouser&password=foopassword");

if(!con.isClosed())
{
trace("Successfully connected to " + "MySQL server using TCP/IP...");

Statement s = con.createStatement ();
s.executeQuery ("MySQL STATMENT HERE");
ResultSet rs = s.getResultSet ();

while (rs.next ())
{
String _room_name = rs.getString("room_name");///as example only... pull whatever data as a test.


}

rs.close();
s.close();
con.close();

}

}
catch(Exception e)
{
trace("Exception::: "+ e.getMessage());

}
finally
{
try
{
if(con != null)
con.close();
}
catch(SQLException e)
{
trace("Exception::: "+ e.getMessage());

}
}


}
private void info(String msg)
{
SmartFoxServer.log.info(msg);
}

@Override
public void handleInternalEvent(InternalEventObject evt)
{

// TODO Auto-generated method stub

}

@Override
public void handleRequest(String arg0, ActionscriptObject arg1, User arg2,
int arg3)
{
// TODO Auto-generated method stub

}

@Override
public void handleRequest(String _command, JSONObject jso, User _user,
int _roomId)
{


}

@Override
public void handleRequest(String arg0, String[] arg1, User arg2, int arg3) {
// TODO Auto-generated method stub

}



}


NOTES:
1. I deleted the internal copy of jre of sfs and symbolically linked pointed to the jre folder of the system
2. mysql-connector-java-5.1.13-bin.jar goes in the {SYSTEM}/jre/lib/ext folder...no where else.
3. for ubuntu using apt-get I had the following packages installed>
openjdk-6-jdk
sun-java6-jre
sun-java6-plugin
sun-java6-bin
sun-java6-jdk
sun-java6-source
sun-java6-fonts
java-common

I am not sure what it is to install it on MAC OS.. but since it is a bastard child of freebsd.. I am sure there is a similar method downloading the package for MAC distribution via the MAC repos.... (hit me if I saying crazy talk)

4. PAPER-ROCK-SCISSORS:::If you are concerned with possibly making mistakes... as they will occur... make sure you have a back-up of the original jre folder just in case nuts and bolts fly everywhere..

5.FINAL NOTE: as a "SANITY" test .. I first compiled a java exectutable with (with a main stub) to test to see if the db runs locally(or elsewhere)

import java.sql.*;
public class jdbc {

public static void main(String[] args) {
Connection con=null;
Class.forName("com.mysql.jdbc.Driver").newInstance ();
con = DriverManager.getConnection("jdbc:odbc:x","root"," xyz");

Statement stmt = con.createStatement();
ResultSet result =stmt.executeQuery("select * from");
while(result.next())
{
System.out.print(result.getString(0));
}
}

}

have fun... should you choose to accept this mission.... :twisted: :twisted: :twisted: :twisted: :wink:

Re: Connecting to MYSQL

Posted: 11 Sep 2010, 22:42
by Eviserator
Caesar wrote:I am been trying to solve this problem for days. Here is my config code

Code: Select all

<DatabaseManager active="true">
<Driver>org.gjt.mm.mysql.Driver</Driver>
<ConnectionString>jdbc:mysql://localhost:80/files</ConnectionString>
<UserName>root</UserName>
<Password>root</Password>
<TestSQL><![CDATA[SELECT COUNT(*) FROM items]]></TestSQL>
<MaxActive>10</MaxActive>
<MaxIdle>10</MaxIdle>
<OnExhaustedPool>fail</OnExhaustedPool>
<BlockTime>5000</BlockTime>
</DatabaseManager>

server error:

Code: Select all

it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFoxServer.java:339)
	at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:607)
Problems in config file: The Test SQL statement failed! Please check your configuration.
it.gotoandplay.smartfoxserver.exceptions.ConfigurationException: The Test SQL statement failed! Please check your configuration.
	at it.gotoandplay.smartfoxserver.lib.ConfigReader.readZoneConfig(ConfigReader.java:199)
	at it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFoxServer.java:339)
	at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:607)

Errors found in configuration files.
Unable to start the server.


Shutting down server...
I use a Mac, and Xampp is my web server. I placed the MYSQL connecter in 'Applications/Utilities'. I recommend you include a detailed article in the documentations for Mac and Windows users.

Also does Smartfox support PHP?
I think you need to alter your connection string a little bit. Try using the IP address with the last bit of info being the database name itself.

Try something like: <ConnectionString>jdbc:mysql://127.0.0.1/databaseName</ConnectionString>

If you are on Mac OS you will also need to put the file: mysql-connector-java-5.1.13-bin in the /Library/Java/Extensions directory. I also copy the org folder to the same directory.

-Skip

MYSQL-SFS

Posted: 12 Sep 2010, 17:44
by d3m0nlogic
Hmm... yep, Skip you are totally right.my apologies...

after I saw the reply again from Eviserator with the trace out.. I do remember that depending on the server setup... and depending on the port and firewall config, and with the assumption that the MySQL is local, SFS ..or more over Java maybe nit picky about calling out to the localhost.

In my case, when I had it first configured, if the binding address in my.cnf for mysql is configured for localhost: bind-address = 127.0.0.1 then like you said...reflect it in sfs config xml... or in my case the code within the abstract extension. If the IP_TABLES are config'd to listen for outside port access:3306, then it is most likely that the bind-address is config'd to the ip-address of the box(local ip). Then the local ip is what you use to connect. For Eviserator, keep in mind that in mysql, the grant perms for an account works best if you nail it down with>grant all on [databas.table] to 'foouser'@'localhost'< and with a another using >grant all on [databas.table] to 'foouser'@'%'.

http://dev.mysql.com/doc/refman/5.1/en/ ... users.html

From the trace out though.... I can't tell if SFS is complaining because of a connection fail or because it doesn't like the test STATEMENT.

it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFoxServer.java:339)
at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:607)
Problems in config file: The Test SQL statement failed! Please check your configuration.

Since I don't know how it was programmed(the sfs classes), I guess the approach would be to take out the test clause and see if it coughs up chunks..if that is possible for DB set-up in the config.xml. I'm guessing that the DB params aren't called(no connection made) unless a sql STATEMENT is made.

just a hunch.... probably no where close to right...