I'm making a multiplayer game server at the moment. Currently it saves each player as a serialized file, I'm looking to convert it to saving everything via MySQL so I can access it all on my website as well.
What I'm wondering, is to write to the serialized file, I use ObjectOutputStream. Below is my method for saving the file.
public static final void storeSerializableClass(Serializable o, File f)
throws IOException {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f));
out.writeObject(o);
out.close();
}
So what I'm wondering, is how would I be able to accomplish that, but saving to SQL, and not serialized? I've been playing with several different things, but I can't seem to find a solid way to do it.
Also I don't need to know how to use MySQL in Java, I know that, I just need to know how I can use ObjectOutputStream with it.
You can store it as a Blob and then deserialize it. There is an example here: http://www.mindfiresolutions.com/Store-Java-Class-Object-in-Database-754.php
Another possibility is to simply store the file as text. It all depends on the requirements.