I am new to GWT. I am trying to connect to it with mysql server.
Below is my project hierarchy:
The name of the project hello, and the name of the package com.hello. By default, GWT creates 3 folders that
- com.hello.client
- com.hello.server
- com.hello.shared
The main java file containing the entry point for GWT is located in the com.hello.client folder named hello.java
I created the db_conn class (the file name is db_conn.java), which contains all the necessary code to connect to the mysql database. This file is placed in a folder com.hello.server. Below is the code
package com.hello.server;
import java.sql.Connection;
import java.sql.DriverManager;
public class db_conn
{
public Connection con;
public db_conn()
{
}
public String ConnectToDB()
{
try
{
String host = "localhost";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "pwd";
Class.forName(driver).newInstance();
con = DriverManager.getConnection(host+db, user, pass);
return "Connected to Database";
}
catch(Exception ex)
{
return ex.toString();
}
}
}
In the hello.java file (which is located in the com.hello.client folder and contains the main entry point for GWT), I imported the class above import com.hello.server.*;
ConnectToDB() db_conn onModuleLoad() hello.java, :
com.hello.server.db_conn can not be found in source packages. Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly.
db_conn, , .
. , .