Ok, here is my situation. I am loading the org.gjt.mm.mysql.Driver. I have the Classpath set correctly. If I run my code as an Application, it works fine. If I change my main to an init() it fails to load the Driver. It's not a Could not Find the Driver, and I don't think it is a Policy or Trust issue, because I have tested it with the appropirate Cert policies and it still does not work. But the Exact Same Code works if it is an Application. Here is my Code
I know it is suposed to work in an Applet. At least according to the tutorial on java.sun.com it is. They have a small section on converting an application to a JDBC APPLET. And this I quote from the source, Applets can usually make network connections to the host they came from, so they can work very well on intranets. Also, from http://java.sun.com/products/jdk/1.1/docs/guide/jdbc/getstart/bridge.doc.html#996918 I have found this quote: JDBC used with a Pure Java JDBC driver works well with applets. So why won't it work??? I'm dying here. Thanks again [ January 14, 2002: Message edited by: Gregg Bolinger ]
Keep in mind I've never done this (been ages since I even attempted an applet) but it seems like the problem is that the MySQL Drivers are not available at the client. Maybe if you merged the applet and JDBC Driver into the same jar and sent this instead (subject to licensing on the JDBC drivers, of course) Can you try it and tell us how you go? Dave.
David: Thanks for trying to lend a hand. Ok, I believe I am already doing this. And, I am running the applet on the web server itself using localhost:3306. So I have not even tried it accross the network yet. This should work first, right? Let me show my directory structure and then my .jar file. C:\JDBC C:\JDBC\tools\ C:\JDBC\classes\ JDBC\*.java --all my .java files tools\mm.mysql.jdbc-1.2c\ --then org.mm..... classes\*.classes -- all my class files when I create my jar file I do this command jar cvf test.jar classes\*.* tools\*.* My applet tag looks like this '<applet code="classes\test.class" archive="test.jar" width=400 height=200></applet>' my test.html file is in the c:\JDBC mysql daemon is running as a service. Then I do appletviewer test.html. It loads with a JButton and when I click on the button I get the unable to load class error message because that is what I tell it to say if an Exception is caught while loading the driver. Here is my code again
Lastly here is my classpath: C:\jdk1.3.1_02\jre\lib\rt.jar;C:\jdk1.3.1_02\jre\lib\i18n.jar;C:\jdk1.3.1_02\lib\dt.jar;C:\jdk1.3.1_02\lib\tools.jar;C:\JDBC\tools\mm.mysql.jdbc-1.2c I am also wondering if there isn't some problem with Class.forName() and executing outside of a main()?? I don't know. Just guessing. Thanks for anything. [ January 14, 2002: Message edited by: Gregg Bolinger ] [ January 14, 2002: Message edited by: Gregg Bolinger ]
The problem is that I don't think browsers use the system classpath. Might be a question for the applet forum as to how browser libraries are managed, but to do it that way you might need to put the driver jar in a browser folder somewhere. (Using the client classpath could cause applets to become unstable or unsafe because the client would dictate the library found rather than the applet.) Dave.
Just to give a bit of clarification: I'm not having a problem with finding the Driver.class. At one time I was getting the Class Not Found error, but after adjusting my CLASSPATH that problem was resolved. So now it is just the fact that it CANNOT LOAD THE DRIVER. And when I print out my exception.message it just names the driver that it can't load. But it DOES FIND the driver. Regarding the applet side and classpath etc as discussed before, I tried using the OBJECT tag instead of the APPLET tag and setting my CODEBASE etc, and that fails in the same way. Also, 99% of my testing on this is in APPLETVIEWER so it is not an IE or NETSCAPE problem. Again, the only part of the code I change is the init() becomes main(String args) and it works like a charm. Thanks for any help.
Ok, after about a week of trial and error, I finally got this thing to work. Originally I was jar-ing my Driver Jar into the mainAp.jar. I kept it seperate this time, and used the archive PARAM to point to it as well as my mainAP.jar and now everything works. I am going to post a new TOPIC with exact instructions on what I did for anyone that wants to give this a try. Thanks for all your help.