Java+MySql

I want to try some online game using only a database.The game will probably be turned based.Anyway … I want to connect to a mysql database from an J2SE application that runs on the user’s computer.
When I try to connect to the database with :


public static void connectToDatabase()
		{
		try
			{
		Class.forName("com.mysql.jdbc.Driver");		
			}					
	catch (ClassNotFoundException e)
			{
			System.err.println("Class not Found : "+ e);
			System.exit(1);
			}
	
		try 
			{
			con=DriverManager.getConnection("jdbc:mysql://db1.xhost.ro/bloodrain_xhost_ro",User,Password);	
			}
		catch(SQLException e)
			{
			System.err.println("SQL Exception : "+ e);	
			System.exit(1);
			}			
		} 

I get the following exception :

http://bloodrain.xhost.ro/exception.jpg

How can I make it work ? ???

a) try http://www.hsqldb.org/
b) the screenshot doesnt work (and most likely png would have been the better choice)

Ooops …sorry . I got that error first time, then it worked.Now it seems it doesn’t work anymore .try http://bloodrain.xhost.ro/ . I’ll try the link. Thanks :slight_smile:

I tried the link.It is an interesting project , but I guess it is slower and smaller than mysql or oracle…

but I guess it is slower

Its surprisingly fast actually… check the benchmarks:
http://www.polepos.org/

Also… if you want to use mysql the users need to run that one, too. Which is sorta shit. Its really far from being practical for a game… eh oh… you want to connect to some remote database. Man… thats scary. Everyone could just sniff user/pass and do something silly with the database. Nah… dont do that. :slight_smile:

Also a lot of users probably cannot connect to the database because of firewall issues (maybe you just hit the same as cause of your error)

I will bother later about security and performance (I heard that SSL can encrypt my password). I am not sure what I want to do so I might make a simple game applet that saves the score . And this shouldn’t be such a bad idea… What about World of Warcraft or Guild Wars . Don’t they use a database to store the positions , the levels etc. ?Anyway …I’ll use this or I don’t , I would still like to know why this is not working.

About the java database , I don’t have enough time to learn that now (School :frowning: ) .

SSL only encrypts traffic, you will still need to store your db password on the client (= very bad idea)
You shouldn’t let clients connect directly to your db, instead let them connect to a a server app which handles things. That server app may use a db as a backend, but then you’re in control of the db traffic (= much lower security risk).

I would like to make the game without a server because I don’t want to keep my pc open all the time.There are programs that make java harder to decompile by adding some assambly code into the source or something like that.
But supposing I’m using the software just for conneting myself to a remote database this should work fine. :’(

You need a server! Otherwise, people just start hacking your database, because you give them the username and password when they download the client. There is NO way to encrypt etc. the password … Encryption does not work that way.

Ok then… I guess that an applet will work the same way :frowning:

You might be able to do something with HTTP posts if you have a web space provider that allows CGI scripts. Then the database access is handled from the CGI web space end.

HTH

Endolf

10x for your answers.It was just for learning purposes so the security it’s not very important. What if I am the only person that has the software that connects to the database ? With or without security this must work somehow…I’ll search more.Thanks again.

There is little gain in trying to do the wrong thing to learn the right thing…

Then just consider it is a server application and I will run this code only on the server so that I can connect to the database .Anyway… someone who saw this topic but it is still waiting the for his account to be approved (I guess it is a bug or something because he says he waits for over 2 weeks…) sent me an email with some explinations.

My Galaxy Traders game server gets all of its data from MySql…very nice and fast. (though I am going to make a version for SGS later). Have a server app that does all the db communication and clients talk with server only.