• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

WAMP/Java/MysqlConnector Issue

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. Hope someone helps me solve this, 'cause I'm going crazy.

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!
 
Marshal
Posts: 28175
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you do need

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.
 
Jose Dobles
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Jose Dobles
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so, in the java code, instead of


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?
 
Paul Clapham
Marshal
Posts: 28175
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes you think that it "timed out"? Was that the actual text of the connection error?

If there was more text, then please post it. It's only fair that we should get a look at the error message you're asking about.
 
Jose Dobles
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, forgot to attach the code. Here it is.

 
Paul Clapham
Marshal
Posts: 28175
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Jose Dobles
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

--EDIT--

Now, the ping works both ways, but still getting the connection timed out error.

--EDIT II--

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.

--EDIT III--

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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic