I'm trying to retrieve data from database with GWT and RPC.
-- public class MySQLConnection extends RemoteServiceServlet implements Connection{private Connection conn = null;private ResultSet rs = null;private PreparedStatement pstmt = null;public static Connection getConnection() throws Exception {String driver = "com.mysql.jdbc.Driver";String url = "jdbc:mysql://localhost:3306/temperature";String username = "root";String password = "123456";Class.forName(driver);Connection conn = DriverManager.getConnection(url, username, password);return conn;}public String[] sensor() throws Exception{String [] user = null;try {conn = getConnection();String query = "SELECT ID, times FROM sensor ORDER BY id DESC LIMIT 1;";pstmt = conn.prepareStatement(query); // create a statementpstmt.setInt(1, 1001); // set input parameterrs = pstmt.executeQuery();// extract data from the ResultSetwhile (rs.next()) {user = new String[] {rs.getString(1),rs.getString(2)};}} catch(SQLException e) {e.printStackTrace();} finally {try {rs.close();pstmt.close();conn.close();} catch (SQLException e) {e.printStackTrace();}}return user;}public String[] sensors() throws Exception{return sensor();}
This is the server side programming where I would return 2 parameters to the client side which will then be shown in the web application. However it is always unsuccessful as it is always onFailure that is occuring.
btnNewButton.addClickListener(new ClickListener() {
public void onClick(Widget event) {
ConnectionAsync Abra =(ConnectionAsync) GWT.create(Connection.class);
ServiceDefTarget target = (ServiceDefTarget) Abra;
String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection";
target.setServiceEntryPoint(moduleRelativeURL);
AsyncCallback callback = new AsyncCallback(){
public void onSuccess (Object result){
textbox2.setText((String)result);
Hi.setText("You Pass!");
}
public void onFailure(Throwable caught) {
Hi.setText("You fail!");
}
};
Abra.sensors(callback);
}
});
This is my program on the client side.
Hope if anyone would help me with this
With Regards,
Zhen Liang
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment