AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

applets and the classes they can access

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Jeff Sandler
Guest





PostPosted: Sat Jan 24, 2004 11:23 pm    Post subject: applets and the classes they can access Reply with quote



I have a question about java applets and their ability to access other
classes. I am trying to write an applet that can connect to a mySQL
database.
As a temporary workaround, I created an application instead of an applet
and added the .jar file to the classpath. Even with it on the
classpath on my local machine, the statement

Class.forName("com.mysql.jdbc.Driver");

causes a java.lang.ClassNotFoundException in an applet. In order to
access the .jar file the way the applet needs to, should I

put the .jar file in the same folder as the applet?
import the .jar file?
do something else?

Here's a bonus question. What exactly is that statement

Class.forName("com.mysql.jdbc.Driver");?

Is is invocation of the method of Class called forName with the argument
in the parenthesis? If so, what does the forName method return or do?
I learned to use this statment from the readme that came with mySQL.

Back to top
Tor Iver Wilhelmsen
Guest





PostPosted: Sun Jan 25, 2004 9:59 am    Post subject: Re: applets and the classes they can access Reply with quote



Jeff Sandler <ffej2ffej (AT) dslextreme (DOT) com> writes:

Quote:
put the .jar file in the same folder as the applet?

Won't help. You need to add it to the archives used, and the "applet"
element uses the "archives" attribute for that. If you use the plugin,
there are some related elements for "object" and "embed" - look at the
code produced by the HTMLConverter.

Quote:
Here's a bonus question. What exactly is that statement

Class.forName("com.mysql.jdbc.Driver");?

It loads the class. In the process of doing that, it calls the class'
static initializers, which are supposed to call

DriverManager.RegisterDriver(new com.mysql.jdbc.Driver());

The reason you do that instead of calling registerDriver yurself is
that it's more dynamic, e.g. you can do

Class.forName(System.getProperty("jdbc.driver.class"));

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.