File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes sendParameter() !?!? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sendParameter() !?!?" Watch "sendParameter() !?!?" New topic
Author

sendParameter() !?!?

Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
Alright, first I'll tell you what my project is:
I am making a game for my web server. Just something simple, 2D, and for fun.
It is based on a MySQL database table. Meaning, they login to the "ranked area" using a php form that access's the database. In the database, there is a username, a password, and a score field. Score, is the one I'm concerned with.

See, I found I way to SEND data to the applet:

Basically, the above echo's, from the database, the user's score in a form which a java applet can use to convert from a parameter to a variable.(getParameter("score")).
That's great and all; it means I can load a score from a database, and use it in my applet to invoke a "rank" or a new "level", etc..

But... what if I want to save the score after they finish playing, back to the database?
Java Applet's can't save to an external file(well it can, but you have to go through a whole bunch of... stuff. And even so, it isn't local.. its on the player's machine.), nor a local one(on server). According to the tutorials used to install and run JDBC, applet's cannot modify data in a database, it can only read it. And if JDBC actually CAN send data to the database, well... that would really stink, because I'm new to JDBC and java connection stuff. It means there isnt a tutorial out there, which makes it virtually impossible for a regular home user to do something of the sort...
Thus, I cannot save the user's new info from the game, to the database!

Now, it would be insane to think that Java Dev's made applet's available to the world, and "forgot" to make the applet able to communicate BOTH ways between applet and server... I mean... if the applet can only read data, and cannot send data... then whats the point of 2d game applet's?
So, that cannot be true.
Somehwere there has to be a way to send data, all off the web server.
Basically:
Website -< Database -< Applet -< File/Cookie/Database/SOMETHING!! =(

If anyone has any idea on how to resolve this, I would be EXTREMELY gratefull.
I know there's a way, but google hasn't been very nice to me today. =(
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
The Yuri,

You need to change your display name to be your actual name. That is one of the policies of this site. You can read more about the policy here http://www.javaranch.com/name.jsp and you can change your display name here http://www.coderanch.com/forums/user/edit

Failure to change your display name can have some serious consquences like...

First Jeanne will ask remind you nicely to change your name.

If you don't then...

Then another moderator will repeat the request and make it clear that you must comply.

And if you still don't...

The moderator warlocks of the underworld will take you away and feast upon your internet soul and you may well be unable to post any more messages.

So all in all it's just easiest to change your display name in a couple of minutes and avoid a lifetime of penance.

As to your question. You haven't made you applet get the data.... you are outputting it directly from PHP. But you can connect to your database directly from your applet and then you can do INSERTS, SELECTS, UPDATES etc to your heart's content.

However, just because you CAN do something does not always mean that you SHOULD. There are rather serious security repercussions to consider when you make a database open to the internet. As you would need to do to connect from an applet so such direct connections are often discouraged.
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
The moderator warlocks of the underworld will take you away and feast upon your internet soul and you may well be unable to post any more messages.

LOL
alright, done. =)


As to your question. You haven't made you applet get the data.... you are outputting it directly from PHP. But you can connect to your database directly from your applet and then you can do INSERTS, SELECTS, UPDATES etc to your heart's content.

However, just because you CAN do something does not always mean that you SHOULD. There are rather serious security repercussions to consider when you make a database open to the internet. As you would need to do to connect from an applet so such direct connections are often discouraged.


Alright ill keep that in mind. Also, do you happen to know where a good example source code for INSERTS, SELECTS, and UPDATES would be?
I have looked through quite a few tutorials and guides, and haven't found one thus far, that does anything more than read data.
I suppose I could download the source for JDBC and find the method that applies to my situation, but it would be nice to see it in action, that way I can get my syntax correct...
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Welcome to JavaRanch Joseph!

I am not sure what kind of tutorial you are looking for. JDBC or SQL? You seem to know some SQL so I guess JDBC. There is a JDBC basics tutorial available at http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html

The Sun tutorials are pretty decent.

Your comment about looking at the source makes me wonder if you have not discovered the joys of the javadoc API. Available online at http://java.sun.com/j2se/1.5.0/docs/api/ and http://java.sun.com/j2se/1.4.2/docs/api/index.html depending on the version you are using.

Well I hope that helps you out a bit. It is kind of late here so I am going to be sleeping now but if you have followup questions then I am sure someone else will be more than happy to help you. (Though it can be quiet on weekends)

Good luck.
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
oh cool, this is good stuff!
Well, i think this will do just fine, so a follow is not neccessary. =)
Thanks for the warm welcome. Ill come back and post every now and then, just to say hello. =)

thanks,
joseph
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
You know what I just realized after reading that tutorial?
JDBC and ODBC drivers are what java somehow mysticly uses to access all of the database functions. And these drivers cost money.... you have to pay for them....
They are like 500 dollars too.
That doesnt make alot of sense! lol!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
these drivers cost money

Not all of them. I think it's only SQLServer that has a need for 3rd party drivers, because the one available from Microsoft is apparently quite buggy. But they have a new one in beta now, which may or may not be of better quality when it is released. In the meantime, have a look at jTDS (on SourceForge), which is a free SQLServer driver of good quality. Or which DB are you using that you think you need a commercial driver for?


Ping & DNS - my free Android networking tools app
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Originally posted by Joseph Meckler:
You know what I just realized after reading that tutorial?
JDBC and ODBC drivers are what java somehow mysticly uses to access all of the database functions. And these drivers cost money.... you have to pay for them....
They are like 500 dollars too.
That doesnt make alot of sense! lol!


As previously stated many vendors provide JDBC drivers for free (because by doing so it encourages development using their systems). Anyway as you seem to be using MySQL there is a free JDBC driver available from MySQl at http://www.mysql.com/products/connector/j/
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Originally posted by Ulf Dittmer:

Not all of them. I think it's only SQLServer that has a need for 3rd party drivers, because the one available from Microsoft is apparently quite buggy. But they have a new one in beta now, which may or may not be of better quality when it is released. In the meantime, have a look at jTDS (on SourceForge), which is a free SQLServer driver of good quality. Or which DB are you using that you think you need a commercial driver for?


Of some hilarity as far as I know the new SQL Server driver for MS is based upon some of the Jtds codebase. I know that at a minimum the MS developers have been in touch with the Jtds developers to help improve the MS product.

In short yet another reason to not touch the MS driver. I was and remain convinced that there is something very fishy about the MS JDBC driver being so bad. Especially in terms of performance vs the ODBC/ADO drivers. I mean perhaps I am paranoid but gee it seems that MS might have some reasons for wanting NET performance to be better than Java when communicating with SQL Server.
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
I mean perhaps I am paranoid but gee it seems that MS might have some reasons for wanting NET performance to be better than Java when communicating with SQL Server.

LOL, i wouldnt doubt that a bit. =P

Yeah, apparently unfortunate, I am using a MySQL database.

And to top it off, I cant get the driver to load up properly(some kind of security error), so im gonna explore that some more.
I guess nothing comes without a price! Wether it be money or lots of time and effort. =D

Ohhh, but it will be so awesome once I get this going. Opens up tons of possibilities for Applets. Whoo!!!
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
ohh, and thanks for all the links. That helps a ton. =)
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
Welp, i figured out the first error. Now im getting a new one: SQLException: No suitable driver. But judging by googles results, careless mistakes are the cause of this.

Just wanted to say thanks. You guys helped ALOT. Couldnt have done it without all those awesome links.

Thanks again.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
If this is part of an applet, there are a number things that can go wrong when trying to access a database. In case your problems persist, post a follow-up in the applet forum, and we'll take it from there.
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
If this is part of an applet, there are a number things that can go wrong when trying to access a database.

No joke! >.<

everytime i solve an error, a new one pops up!
Now Im getting this 20 page long stacktrace, with some kind of communications exception.
LOL, all I have to do is change one variable... ONE variable, and the program is altered in its entirety. its the url.(im sure you knew)
wowowowow...

man... once I figure this out, im going to make some sort of class that allows people to do this easier. The tutorials are misleading(the mysql website has information deeper in its tutorials that is alot different from the installation instructions), and even when you use it's information, it still doesn't work. Somebody needs to do somethin about all this. =/

Owell, Im gonna keep trying to fix this, and if I get stumped, ill come make a post in the applet section. Thanks for incentive to help
[ January 09, 2006: Message edited by: Joseph Meckler ]
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
haha!
Anyone ever gotten so fed up, that all you can do is laugh?
(<=-- sarcastic grin =P)

*sigh*
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
If I could make a wild and crazy suggestion here... why don't you make it work first in a application and then an applet. The reason I suggest this is that as mentioned there are bunch of special security related things that can trip you up in applets but if you get the feel of what you are doing in just a simple application first then it will be less overwhelming.

Like just a simple program that connects, creates a result set and prints out to the console would be good for some basics.
Joseph Meckler
Greenhorn

Joined: Jan 06, 2006
Posts: 10
Thats a great idea. That way i can get a hold of what im actually doing here. Then go after the buggy applets.
Alright, thanks for suggestion!


*edit*
Welp, what that did for me is show me what the true error is. I think the server is denying my request to access the database for some reason. It keeps telling me access is denied. Odd.
[ January 09, 2006: Message edited by: Joseph Meckler ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: sendParameter() !?!?