Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2009

Tip: Looking for answers? Try searching our database.

Class.forName

Thread view: 
tamasu - 02 Nov 2009 20:11 GMT
Hi,

First of all I am new to java. I would like to connect to a database
using the Class.forName method but I am having some difficulties

If the said method is set in the main form everything works as it
should but if I can't figure out how I can instansiated through a
class. I am receiving java.lang.ClassNotFoundException

I can confirm that the driver is correct as I managed to connect
through netbeans using the same driver details

The driver I am using is - com.mysql.jdbc.Driver and the ConnectionUrl
is jdbc:mysql://localhost/<DatabaseName>

Any ideas?

Kind Regards
Jansen
Lew - 02 Nov 2009 20:40 GMT
> First of all I am new to [J]ava. I would like to connect to a database
> using the Class.forName method but I am having some difficulties
>
> If the said method is set in the main form everything works as it
> should but if I can't figure out how I can instansiated through a
> class. I am receiving java.lang.ClassNotFoundException

Can you be more specific as to what you mean by instantiating "through
a class"?  Technically, loading the driver "in the main form" is
loading it through a class.  As another technical nit, it's not
instantiating anything to call 'Class.forName()', just loading the
driver class.

The way to load the driver is to make sure that at some point before
you need database access some method is called that in turn calls
'Class.forName()' for the driver.

Has your study of Java so far taught you the difference between static
methods and instance methods?

--
Lew
Lew - 02 Nov 2009 20:41 GMT
> If the said method is set in the main form everything works as it
> should but if I can't figure out how I can instansiated through a
> class. I am receiving java.lang.ClassNotFoundException

I forgot to mention about ClassNotFoundException that either the fully-
qualified name (FQN) of the driver class is wrong or it's not in the
class path for the Java run.

--
Lew
John B. Matthews - 02 Nov 2009 21:57 GMT
In article
<69da9f94-c5f7-4b17-8377-7de63e05ceef@a31g2000yqn.googlegroups.com>,

Please do not multi-post:

<http://groups.google.com/group/comp.lang.java.databases/browse_frm/thread/6e661f
b7ca5e0829
>

Signature

John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Roedy Green - 03 Nov 2009 03:05 GMT
On Mon, 2 Nov 2009 12:11:54 -0800 (PST), tamasu
<tamasumalta@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>. I am receiving java.lang.ClassNotFoundException

the driver you load must exist in a jar on the classpath or in the
ext directory.

see
http://mindprod.com/jgloss/runerrormessages.html#CLASSNOTFOUNDEXCEPTION
http://mindprod.com/jgloss/classpath.html
Signature

Roedy Green Canadian Mind Products
http://mindprod.com

An example (complete and annotated) is worth 1000 lines of BNF.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.