Re: JDBC Error:The method forName(String) is undefined for the type Class

574 views
Skip to first unread message
Message has been deleted

Reinier Zwitserloot

unread,
Aug 30, 2008, 1:01:45 AM8/30/08
to Google Web Toolkit
Alex, I don't think you understand what GWT is.

GWT compiles java code into javascript, so that a plain jane vanilla
webbrowser can run it.

Your code snippet suggests that you think that a web browser can
connect to a MySQL server running on the web browser user's localhost
at port 3306.

I trust that reading the above sentence a few times will make you see
the light.

To do db stuff with GWT, you do the db stuff on your *SERVER*. All the
client does, is render things, and communicate with your server. In
other words, run the above code on the server (which has nothing to do
with GWT, GWT just does the client side stuff).

On Aug 30, 4:13 am, Alex Luya <alexander.l...@gmail.com> wrote:
> Hello
>      Use following code(2) connect to mysql,and I have get excepted
> date,but there is an error(1),can anybody tell me why?thank you.
> (1)error
>
> [ERROR] Line 30: The method forName(String) is undefined for the type Class
>
> (2)connection code
> public static Connection getConnection()
>     {
>         System.out.println("MySQL Connect Example.");
>         Connection conn = null;
>         String url = "jdbc:mysql://localhost:3306/";
>         String dbName = "Test";
>         String driver = "com.mysql.jdbc.Driver";
>         String userName = "root";
>         String password = "pwdpwd";
>         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();
>         }
>         return conn;
>     }
Reply all
Reply to author
Forward
0 new messages