开发者

GWT JDBC how can i do?

i am learning gwt and i'm getting troubles trying to do a query No source code is available for type [package.Class]; did you forget to inherit a required module?

i dont understand very well how works a module

do i have to write a module for each class?

i just wanna call a class to insert data

Thanks for ad开发者_如何转开发vance


GWT is ultimately compiled into Javascript. It's not possible to make a direct JDBC connection from Javascript. Therefore, to make a database connection, you'll have to communicate with a server.


In order to connect database you should learn RPC after you learn it,you can create a class which can service class which implemtent like that

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;
   }
}

In this code you can insert a person object to database

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜