Re: RPC fails
Server side:
package main.server;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import main.client.GreetingService;
import main.client.User;
import main.shared.FieldVerifier;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class MySQLConnection extends RemoteServiceServlet implements
GreetingService {
private Connection conn = null;
private String status;
private String url = "jdbc:mysql://localhost/testdb";
private String user = "root";
private String pass = "root";
public MySQLConnection() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, user, pass);
} catch (Exception e) {
System.out.println("Failed to connect!");
//NEVER catch exceptions like this
}
}
public User greetServer(String user, String pass) throws IllegalArgumentException {
System.out.print("inside greetServer");
User u = new User("user", "pass");
try {
PreparedStatement ps = conn.prepareStatement("select readonly * from users where username = \"" + user + "\" AND " + "password = \"" + pass + "\"");
ResultSet result = ps.executeQuery();
while (result.next()) {
u = new User(result.getString(1), result.getString(2));
}
result.close();
ps.close();
} catch (SQLException sqle) {
System.out.println("user not found!");
}
return u;
}
/**
* Escape an html string. Escaping data received from the client helps to
* prevent cross-site script vulnerabilities.
*
* @param html the html string to escape
* @return the escaped string
*/
private String escapeHtml(String html) {
if (html == null) {
return null;
}
return html.replaceAll("&", "&").replaceAll("<", "<")
.replaceAll(">", ">");
}
}
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/j3EjYkkhxUUJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home