The method forName(String) is undefined for the type Class !!!

1,804 views
Skip to first unread message

keith...@gmail.com

unread,
Jan 22, 2009, 10:15:05 PM1/22/09
to Google Web Toolkit
Hi
I'm pretty new at the GWT, but have been using java for a few years.
For whatever reason, I simply CANNOT get around this dumb error.
Every example of using the mysql jdbc connector uses the Class.forName
("com.mysql.jdbc.Driver") in it, but whenever I try to run this, I
always get this:

The method forName(String) is undefined for the type Class

This happens on Linux, Windows, in Netscape, and Eclipse.

WHAT am I missing?

Here's the latest sample I tried, which I got online.

public void connecter() {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url
+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}

????????????????????????????????

At ONE point the other day I was able to establish a connection to
mysql.... running it on my linux machine, from eclipse. But now I've
somehow broken that magical configuration and can't get it back.

Any help would be greatly appreciated.
Thanks

Litty Preeth

unread,
Jan 22, 2009, 11:29:34 PM1/22/09
to Google-We...@googlegroups.com
This code is where? in ur client side GWT code or server side? You cant use Class.forName in GWT. Remember GWT code is eventually to get converted into JS. Refer the following for the supported JRE lib emulations in GWT:
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=RefJreEmulation

- Litty Preeth

keith...@gmail.com

unread,
Jan 23, 2009, 11:34:56 AM1/23/09
to Google Web Toolkit
Hi
Thanks for the reply.
I know that the GWT stuff gets converted to JS.
I'm trying to build a connector such that the browser will retrieve
data from mysql, which resides on the same server.
If this connector code isn't to be used within GWT, where would it be
used?



On Jan 22, 9:29 pm, Litty Preeth <preeth.h...@gmail.com> wrote:
> This code is where? in ur client side GWT code or server side? You cant use
> Class.forName in GWT. Remember GWT code is eventually to get converted into
> JS. Refer the following for the supported JRE lib emulations in GWT:http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=goog...
>
> - Litty Preeth
>
> On Fri, Jan 23, 2009 at 8:45 AM, keith.m...@gmail.com
> <keith.m...@gmail.com>wrote:

Lothar Kimmeringer

unread,
Jan 23, 2009, 11:42:18 AM1/23/09
to Google-We...@googlegroups.com
keith...@gmail.com schrieb:

> I'm trying to build a connector such that the browser will retrieve
> data from mysql, which resides on the same server.
> If this connector code isn't to be used within GWT, where would it be
> used?

The connector has to be used in the classes that reside on the server-side
only, so if you put the class into the client-package or another package
you added to the list of source-paths in the GWT-XML you will run into
problems.

If you are sure that you use these classes in server-classes only,
you might post your GWT.xml here, so we can check if you mis-
configured something letting the GWT-compiler think that the
server-package should be compiled to JS.


Regards, Lothar

keith...@gmail.com

unread,
Jan 23, 2009, 12:16:47 PM1/23/09
to Google Web Toolkit
I'm not sure I'm doing it right....

I've been trying to put the connector in the same class as the client
code which tries to connect and retrieve records and etc.
If I put the connector in a class which resided on the server, would I
then just import that in the client class in order to use its methods?

It would be nice if there were a complete working example somewhere
online!

Thanks again for your help
Keith




On Jan 23, 9:42 am, Lothar Kimmeringer <j...@kimmeringer.de> wrote:
> keith.m...@gmail.com schrieb:

Ian Petersen

unread,
Jan 23, 2009, 12:32:33 PM1/23/09
to Google-We...@googlegroups.com
On Fri, Jan 23, 2009 at 9:16 AM, keith...@gmail.com
<keith...@gmail.com> wrote:
> I'm not sure I'm doing it right....

You're definitely doing it wrong.

> I've been trying to put the connector in the same class as the client
> code which tries to connect and retrieve records and etc.
> If I put the connector in a class which resided on the server, would I
> then just import that in the client class in order to use its methods?

Nope--all direct DB communication must remain on the server. There's
no way to run JDBC-over-HTTP, and the client code runs in the browser.

> It would be nice if there were a complete working example somewhere
> online!

Search the mailing list history for JDBC, database connection, etc.
This topic comes up quite frequently as new users try to connect to a
database for the first time.

The quick summary is that only the server can talk to the DB. If you
have a choice of back-end technology, Java is the easiest because then
you can use GWT-RPC to talk to the back end and you have all of JDBC
available to you on the server. If you don't have a choice and Java
is not on the table for server-side tech, you'll have to come up with
an alternate to GWT-RPC and JDBC, but there's lots of choice in both
spaces.

Ian

keith...@gmail.com

unread,
Jan 23, 2009, 1:13:39 PM1/23/09
to Google Web Toolkit
OK
SO..... I think I might have found something....

http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=GettingStartedRPC

This Getting Started thing, looks like it's how I would go about
creating the server-side stuff.
Does this look like the right direction for me to start.... building
the server-side interface, having the connector in there?
Thanks!



On Jan 23, 10:32 am, Ian Petersen <ispet...@gmail.com> wrote:
> On Fri, Jan 23, 2009 at 9:16 AM, keith.m...@gmail.com

Ian Petersen

unread,
Jan 23, 2009, 1:19:08 PM1/23/09
to Google-We...@googlegroups.com
On Fri, Jan 23, 2009 at 10:13 AM, keith...@gmail.com
<keith...@gmail.com> wrote:
> This Getting Started thing, looks like it's how I would go about
> creating the server-side stuff.
> Does this look like the right direction for me to start.... building
> the server-side interface, having the connector in there?

Yep.

keith...@gmail.com

unread,
Jan 23, 2009, 1:50:39 PM1/23/09
to Google Web Toolkit
Great!
Thanks.... I'll persue it this route... this makes sense now.
From the examples I'd seen online thus far, it looked like all the
code was in the GWT.
Thanks again.


On Jan 23, 11:19 am, Ian Petersen <ispet...@gmail.com> wrote:
> On Fri, Jan 23, 2009 at 10:13 AM, keith.m...@gmail.com
Reply all
Reply to author
Forward
0 new messages