GWT JDBC怎么办?

时间:2010-07-19 18:07:13

标签: gwt

我正在学习gwt而且我在尝试查询时遇到了麻烦 没有源代码可用于[package.Class]类型;你忘了继承一个必需的模块吗?

我不太了解模块是如何工作的

我是否必须为每个班级编写一个模块?

我只想调用一个类来插入数据

感谢您提前

2 个答案:

答案 0 :(得分:4)

GWT最终是compiled into Javascript。无法从Javascript直接建立JDBC连接。因此,要建立数据库连接,您必须communicate with a server

答案 1 :(得分:0)

为了连接数据库,你应该在学习之后学习RPC,你可以创建一个可以为类实现的服务类的类

public class ExampleServiceImpl  extends RemoteServiceServlet implements ExampleService{

//private Connection con=null;
    private String status;
    private String url="jdbc:mysql://localhost:3306/test";
    private String user="test";
    private String pass = "";
    private  Person people;
    private ResultSet resultSet=null;
    private Statement stm=null;
    private Connection con=null;

    private Statement stm2=null;
    private Connection conn2=null;
     private ResultSet resultSet2=null;
    private MySqlConnection conn=new MySqlConnection();


@Override
public Person getPerson(String name,String surname,int password) {
    Person personinfo=new Person();
    personinfo.setName(name);
    personinfo.setSurname(surname);
    personinfo.setPassword(password);

    ResultSet resultSet=null;
    Statement stm=null;
    Connection con=null;

     MySqlConnection conn=new MySqlConnection();     
      con = conn.getConnection();

        stm = ((Connection) con).createStatement();

     String sorgu = "SELECT * FROM person";

        resultSet = stm.executeQuery(sorgu);

   while(true){
     String sql = "INSERT INTO person " +
               "VALUES ("+ password +", '" + name+ "','" + surname + "')";


        stm.executeUpdate(sql);

        ((Connection) con).setAutoCommit(false);

        ((Connection) con).commit();
    stm.close();


    return personinfo;
   }
}

在此代码中,您可以将人物对象插入数据库