Connect to MySQL and Running Example

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
zkidkid
Posts: 39
Joined: 21 Mar 2011, 12:26
Contact:

Connect to MySQL and Running Example

Post by zkidkid »

Hi All,
I'm new with SFS.
I have just installed and run some examples.

Currently, when I run example here: http://112.213.88.17:8080/Examples/AS2/ ... Extension/

I got error :
"Error in extension [ dbExtension.as ]: TypeError: Cannot call method "executeQuery" of null (dbExtension.as#1649) Internal: 74 -- Line number: 73 in file: dbExtension.as"

So I have put a trace to check in server code:

Code: Select all

function handleRequest(cmd, params, user, fromRoom)
{
 trace("begin handle request" + cmd)
	if (cmd == "getData")
	{
		var t1 = getTimer()
		trace("begin select")
		// create a SQL statement
		var sql = "SELECT * FROM contacts ORDER BY name"		
But it didn't work. I see nothing in Logs windows.

I need some help for 2 questions:
#1: How could I debug as script in server code ? Could I put some breakpoint ?
#2: How could I connect to mysql database ? Do there have any tutorial for beginner like me ?

Thanks.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

"Error in extension [ dbExtension.as ]: TypeError: Cannot call method "executeQuery" of null (dbExtension.as#1649) Internal: 74 -- Line number: 73 in file: dbExtension.as"
This could mean that your database manager instance have not been initialized yet, or that you have not yet defined or enabled the DatabaseManager for your zone inside config.xml

Code: Select all

dbase = null;
dbase.executeQuery(...);
would generate that same error.
How could I debug as script in server code ? Could I put some breakpoint ?
As far as I know, you can't debug actionscript extension. Painful, I know - you'll have to use traces. You can however debug java extensions.
How could I connect to mysql database ? Do there have any tutorial for beginner like me ?
Yup, there's plenty of database tutorials and they can be found in chapter 8 of the online [url=ttp://www.smartfoxserver.com/docs/]documentation[/url].
Smartfox's forum is my daily newspaper.
zkidkid
Posts: 39
Joined: 21 Mar 2011, 12:26
Contact:

Post by zkidkid »

Hi, Thanks for your quick reply.

I has tried to config it again. but now I can't start SFS. It give a error like that
"Test SQL statement fail
...
Errors found in configuration files.
Unable to start the sever"

there is my config:

Code: Select all

<Zone name="dbZone" customLogin="false" buddyList="20">
			<Rooms>
				<Room name="MainRoom" maxUsers="10" isPrivate="false" isTemp="false" autoJoin="true" />
			</Rooms>
			
			<Extensions>
				<extension name="dbTest"  className="dbExtension.as" type="script" />
				<extension name="dbTestAdv"  className="dbExtensionAdv.as" type="script" />
				<extension name="simpleExt"  className="simpleExt.as" type="script" /> 
			</Extensions>
			
			<DatabaseManager active="true">
				<!--
				<Driver>sun.jdbc.odbc.JdbcOdbcDriver</Driver>
				<ConnectionString>jdbc:odbc:sfsTest</ConnectionString>
				-->
				<!--
				Example connecting to MySQL
				-->
				<Driver>org.gjt.mm.mysql.Driver</Driver>
				<ConnectionString>jdbc:mysql://112.213.88.17:2222/zkidkid_database</ConnectionString>
				
				
				<UserName>****</UserName>
				<Password>****</Password>
				
				<TestSQL><![CDATA[SELECT COUNT(*) FROM TBL_TEST]]></TestSQL>
				
				<MaxActive>10</MaxActive>
				<MaxIdle>10</MaxIdle>
				
				<OnExhaustedPool>fail</OnExhaustedPool>
				<BlockTime>5000</BlockTime>
					
			</DatabaseManager>
		</Zone>
I am being confuse at the connection string. But I don't know what should I put there.

I have a hosting at http://112.213.88.17:2222
After I log in, I have created a db call zkidkid_database and the user + password.

So what should I put there ?

Thanks in advance.

P/S: Sorry for my poor English. tell me if something makes you confuse.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

I think it's due to not having mySQL driver installed (which is the common cause)

Firstly, download mySQL driver from: http://www.mysql.com/downloads/connector/j/ and follow the instructions from: http://forums.smartfoxserver.com/viewtopic.php?t=1878
Smartfox's forum is my daily newspaper.
deux
Posts: 21
Joined: 15 Dec 2010, 07:48

Post by deux »

zkidkid wrote: #2: How could I connect to mysql database ? Do there have any tutorial for beginner like me ?
here some tutorial from makzan for beginner like us...
hope it'll helpfull for you :D
zkidkid
Posts: 39
Joined: 21 Mar 2011, 12:26
Contact:

Post by zkidkid »

hey BigFish

So many thanks for your quick reply.
I have downloaded MySql and follow your link to add to smartfoxserver.
But I got a error at config file.

Code: Select all


--- [ Zones & Rooms ] -------------------------------------

19:48:26.261 - [ INFO ] > Default Buddy List Persister <INITED>
Zone: simpleChat

        The Hall           (id: 1, max: 50, pass:N)
        The Kitchen        (id: 2, max: 50, pass:N)
        The Garden         (id: 3, max: 50, pass:N)
        The Bathroom       (id: 4, max: 50, pass:N)
        The Garage         (id: 5, max: 50, pass:N)
        The Living Room    (id: 6, max: 50, pass:Y)
19:48:26.593 - [ INFO ] > Zone Extension [ json ] created, for zone:simpleChat
[jsonSample.as]: JSON Example initialized

19:48:26.598 - [ INFO ] > Default Buddy List Persister <INITED>
java.lang.NullPointerException
        at it.gotoandplay.smartfoxserver.SmartFoxServer.setupZone(SmartFoxServer
.java:1784)
        at it.gotoandplay.smartfoxserver.lib.ConfigReader.parse_Zones(ConfigRead
er.java:806)
        at it.gotoandplay.smartfoxserver.lib.ConfigReader.readZoneConfig(ConfigR
eader.java:174)
        at it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFo
xServer.java:339)
        at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:
607)
Problems in config file: null
it.gotoandplay.smartfoxserver.exceptions.ConfigurationException
        at it.gotoandplay.smartfoxserver.lib.ConfigReader.readZoneConfig(ConfigR
eader.java:199)
        at it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFo
xServer.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 don't know what wrong with it now ?


It's my config file:

<DatabaseManager active="true">
				<!--
				<Driver>sun.jdbc.odbc.JdbcOdbcDriver</Driver>
				<ConnectionString>jdbc:odbc:sfsTest</ConnectionString>
				-->
				<!--
				Example connecting to MySQL
				-->
				<Driver>org.gjt.mm.mysql.Driver</Driver>
				<ConnectionString>jdbc:mysql://112.213.88.17:3306/zkidkid_database</ConnectionString>
				
				
				<UserName>zkidkid_username</UserName>
				<Password>sharetobeshared</Password>
				
				<TestSQL><![CDATA[SELECT COUNT(*) FROM TBL_TEST]]></TestSQL>
				
				<MaxActive>10</MaxActive>
				<MaxIdle>10</MaxIdle>
				
				<OnExhaustedPool>fail</OnExhaustedPool>
				<BlockTime>5000</BlockTime>
					
			</DatabaseManager>
		</Zone>

To add MySQL, I have downloaded it from your link. and add to wrapper.conf like that :

wrapper.java.classpath.38=lib/lsc.jar
wrapper.java.classpath.39=lib/commons-io-1.4.jar
wrapper.java.classpath.40=lib/mysql-connector-java-5.1.15-bin.jar

the mysql-connector-java-5.1.15-bin.jar is the file I has extracted from the download packet. And copy it to xxx/server/lib/

Need your help urgently.

Thanks so much.

Kidkid.
zkidkid
Posts: 39
Joined: 21 Mar 2011, 12:26
Contact:

Post by zkidkid »

Hi many thanks. Maybe it's work right now.
just a error:

Code: Select all


20:00:52.987 - [ INFO ] > Default Buddy List Persister <INITED>
        DB Manager Activated ( org.gjt.mm.mysql.Driver )
20:00:53.164 - [ SEVERE ] > DbManager could not retrive a connection. java.sql.S
QLException: null,  message from server: "Host '113.161.74.114' is not allowed t
o connect to this MySQL server"
it.gotoandplay.smartfoxserver.exceptions.DbManagerException: The Test SQL statem
ent failed! Please check your configuration.
        at it.gotoandplay.smartfoxserver.SmartFoxServer.setupZone(SmartFoxServer
.java:1843)
        at it.gotoandplay.smartfoxserver.lib.ConfigReader.parse_Zones(ConfigRead
er.java:806)
        at it.gotoandplay.smartfoxserver.lib.ConfigReader.readZoneConfig(ConfigR
eader.java:174)
        at it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFo
xServer.java:339)
        at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:
607)
Problems in config file: The Test SQL statement failed! Please check your config
uration.
it.gotoandplay.smartfoxserver.exceptions.ConfigurationException: The Test SQL st
atement failed! Please check your configuration.
        at it.gotoandplay.smartfoxserver.lib.ConfigReader.readZoneConfig(ConfigR
eader.java:199)
        at it.gotoandplay.smartfoxserver.SmartFoxServer.initServerSocket(SmartFo
xServer.java:339)
        at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:
607)

Errors found in configuration files.
Unable to start the server.
I will just try to apache and try it again. thanks
zkidkid
Posts: 39
Joined: 21 Mar 2011, 12:26
Contact:

Post by zkidkid »

So many thanks.
I have add my current IP in MySQL Management so it's fine right now.
Thanks you so much.
Flappi282
Posts: 158
Joined: 20 May 2009, 17:51
Contact:

Post by Flappi282 »

Just one question, a bit off topic, but did you know you're using a name very similar to my alternative one? I don't mind it, but just asking.
--
Flappi282
Post Reply