I'm starting a high traffic web application.  I just setup a MySQL
server for GWT app.

1.  Is the practical way still opening and closing a connection like
below?  What about database connectivity with RPC?  Below, for every
RPC service method call, I open a database connection, make a query,
and close connection.  Is there a good practice way a web app is doing
database connectivity?  Should I leave the connection open in the RPC
service since there will be a lot of RPC calls and just change the
query string?


public class DB_QueryTest {
                public static String query() {
                       String Query = "SELECT * FROM `tester`;";
                       String resultString = "";
                       try {
                             Connection connection = DB_Conn.getConn();
                             Statement select = connection.createStatement();
                             ResultSet result = select.executeQuery(Query);

                             while (result.next()) {
                                resultString += result.getString(1);
                             }
                             connection.close();

                       } catch(Exception e) {
                             e.printStackTrace();
                       }
                      return resultString;
                }
}

-----------------------------------------------------------------------------------------------------------------------------------

//GreetingServiceImpl.java from GWT 1.6 RPC example, called when Send
button is clicked
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet
implements
                GreetingService {
        public String greetServer(String input) {
                String serverInfo = getServletContext().getServerInfo();
                String userAgent = 
getThreadLocalRequest().getHeader("User-Agent");

                count++;
                return "Hello, " + input + "!<br><br>I am running " + serverInfo
                                + ".<br><br>It looks like you are using:<br>" + 
userAgent
                                + "<br><br>My Query: " + DB_QueryTest.query();
        }
}



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to