我使用的是GWT(Google Web Tool-Kit)2.5.1版。我已经完成了开发示例应用程序以显示该用户名和密码。但我不知道如何使用Hiberante的JDBC将这些值插入到MySQL数据库表中。任何机构都知道,请发给我完整的代码。
这是我的邮箱号码: subbareddyroyal@gmail.com
谢谢&问候
Subbareddy.N
答案 0 :(得分:0)
GWT不是Java应用程序环境。它编译为javascript。您必须将数据发送到在完整JVM中运行的Java服务器。
答案 1 :(得分:0)
上面我发布了这个问题。我自己找到了通过使用jdbc,GWT和HTML将值插入我的sql数据库的答案。 在这里,我发布了我在申请中发生的变化。
在gwt应用程序的服务器文件夹下的impl类中添加以下插入。
public void insert(String name) throws CommunicationsException {
try {
System.out.println("Before loading the driver class");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("after loading the driver ");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/gwt", "root", "root");
System.out.println("after creating the connection");
PreparedStatement ps = con
.prepareStatement("insert into gwt_user(userName)values(?)");
System.out.println("after loading the query");
ps.setString(1, name);
int i = ps.executeUpdate();
if (i < 0) {
return;
}
} catch (SQLException e) {
System.out.println(e);
}
}
之后,您可以在impl类下的ur greetserver(可选Name)方法中添加以下try catch块。
try {
insert(name);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
然后剩下的所有文件都是相同的。不需要更改应用程序中的任何文件