• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet to Php to MySql

 
Lyn Emmilie
Greenhorn
Posts: 5
Java MyEclipse IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

First of all, I just joined the ranch
Pardon me if my question has been answered before, because I have searched through the forum and there was none that could answer my problem
(or none that I understand)

I'm creating a game where at the end, I'll send an int score and String name to a php which will store it in web database.
I'm using a paid server for this.

I have a Java applet that is embedded in a mypage.com/play.php
I have a php for retrieving the url from the applet (or so it seems..) in mypage.com/test.php

Basically I followed this tutorial from http://woogley.net/misc/Highscore/
Now the Java console tells me java.lang.ArrayIndexOutOfBoundsException: 0
which comes from the line from Save.java

My DBComm looks like this


While this is my Save.java


I know no one likes to debug someone else's code, but I'm still open to any other suggestions and I want to learn,
honestly, this is my first time doing networking with applet, so I'm not sure where to start and why to use what packages.

I'm thinking of other ways, such as storing the scores in a .txt file in the same directory (eg: mypage.com/score.txt)
and use php to use them later.
But I'm not sure how

Thanks

 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which code is leading the exception DBComm or Save?
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as[0], are you sure that length of as is >0? Another point, the way you are comparing string
as[0]=="0" // this is a reference comparison not a value comparison, you need to use the equals method

as[0].equals("0")
 
Lyn Emmilie
Greenhorn
Posts: 5
Java MyEclipse IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:Which code is leading the exception DBComm or Save?

I already marked it in my Save.

Swastik Dey wrote:as[0], are you sure that length of as is >0? Another point, the way you are comparing string
as[0]=="0" // this is a reference comparison not a value comparison, you need to use the equals method

as[0].equals("0")


It originally is as[0].equals("0")
it didnt work, spits out the same java.lang.ArrayIndexOutOfBoundsException so i tried to change it to as[0]=="0"
also, the same error.

like I said, I'm not sure of the code since I got it from http://woogley.net/misc/Highscore/

I especially not know the purpose of the arraylist in the first place. What it's supposed to contain, huh?

Thanks for replying
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my understanding, the number of lines to be returned from server is not known, that's why the ArrayList is being used.
 
Lyn Emmilie
Greenhorn
Posts: 5
Java MyEclipse IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense. In this case I'm not sure what should the arraylist carry anyway

Hey I have a new code, which isn't working well but can you help me, Swastik?
I got this from http://www.coderanch.com/t/437651/Applets/java/Applet-PHP
but he used getCodeBase()

Is my URL in the correct format?
I have my php file at mypage.com/test2.php where I receive 2 variables as POST



and my test2.php


Then when I call the postResults method, nothing happens. My console also isn't showing any error, and nothing is stored in my database >_<

Sorry if this is taking your time.. I really appreciate that you try to help ^^
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know much about php, however the java code is looking fine to me. What error are you getting?
 
Lyn Emmilie
Greenhorn
Posts: 5
Java MyEclipse IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I see..

That's the thing, I'm not getting any error so I don't know where to look.
Is the Java supposed to work?
I mean,
my applet is trying to connect to the URL.. maybe it didnt succeed?
 
Swastik Dey
Rancher
Posts: 1643
6
Android Java Java ME
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be. As far as the java code is concerned, nothing looks wrong with the connectivity part.
 
Lyn Emmilie
Greenhorn
Posts: 5
Java MyEclipse IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh you're right.
It's the php after all. A little mistake at the Insert statement.
I'll edit the code for the purpose of others to learn.

Thanks for reviewing my Java code, Swastik
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic