I'm using WAMP and Netbeans on Windows XP. I created a japplet that connects to my database and allows queries and all that mysql stuff. When I run the applet on netbeans, it's perfect. Here's the code that connects:
I'm using the mysql-connector-java-5.0.8-bin.jar. I've added the .jar to the path. Also, here's my html code.
When I run the applet on firefox, I get this error:
I also tried using the archive = "mysql-connector-java-5.0.8-bin.jar" and nothing. Also, on netbeans, I added the .jar to the libraries that the project uses, but to no use.
The project is saved in C:\wamp\www\applets\Funcionarios\JavaApplication2 and I've placed the mysql-connector-java-5.0.8-bin.jar inside the JavaApplication2 file.
Any ideas? Thanks!
but then you have to put that jar file in the right place so it can be downloaded from your web server. You should be able to type the URL for the jar file into the browser and see it trying to download the jar.
As for Netbeans, forget about that. Netbeans is where you develop code, but it's up to you to make sure that you deploy all of the code to the right place. You can't expect Netbeans to do that.
One other thing:
This line of code tells the JDBC driver to look for the database on the same machine where the code is running. If you're writing an applet then that's the client's machine, the computer of whoever downloaded your applet. They aren't likely to be running MySQL on their computers.
So you should change that to point to your computer, not theirs.
Joined: Feb 17, 2011
Ok, so I have to use the "archive" to point at the .jar. And in the url, I should put the server's IP, not localhost... Makes sense! I'll try and let you know if this works. Thanks!
I used the server's IP address. Also, I extracted the driver .jar and placed it in the same folder where the applet is. I also made sure that you could download the driver from the browser, as you said. And in the applet, I used the 'archive' to point at the driver. Then, I granted all privileges to the app and it works perfectly... if run from the server. But when I run the applet from another pc, it gets the connection timed out: connect error. Any ideas on this?
Okay. So from the computer where that error occurred, is there an unobstructed network path to whatever you named your server in the JDBC URL? Can you ping that name from the client computer? Or is there perhaps a firewall or some other network component blocking the path?
Joined: Feb 17, 2011
For some reason, I can ping from the client to the server, but I can't ping from the server to the client. I'm overlooking something, because it seems that the server is the only pc in the network that can't ping.
Now, the ping works both ways, but still getting the connection timed out error.
I disabled the firewalls on both computers, and the applet works perfectly. It has to be a firewall issue, obviously. I'll work on this and let you know.
Done. Works like a charm. I'll leave a summary here just in case someone with the same issue finds this thread:
In the java code, the url for the mysql connection has to be the server's IP, not "localhost". Also, if using WAMP, make sure that in the wamp\www\administrator folder, you create a folder for the applets (say, c:\WAMP\www\administrator\applets). Inside the applets file, next to the .class that is created from building the applet, extract the mysql connector .jar. Make sure you can download the .jar from the browser like this:
http://localhost/administrator/applets/com/classes/com/mysql/jdbc/driver.class (NOTE: I'm assumming that when extracting the mysql connector driver .jar file, the com/mysql/jdbc folders are created).
As for the applet itself:
The CODE must be the .class created by compiling and building the java. CODEBASE must be the location of the .class. (NOTE: The codebase has a '.' at the beginning cuz the codebase starts by default from the C:\wamp\www folder. In other words, '.' stands for C:\wamp\www, so actually, the codebase is C:\wamp\www\administrator\applets...etc.) At last, make sure that the firewall allows access from other computers. Otherwise, you'll get a connection time out error.
And that should do it! Thanks to Paul Clapham for the help!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com