Hey,
Here is some of the code that I had written for the application based
on a mysql test database with one table that has three fields (id,
firstname, lastname). The name of the project is library application.
for the server side, this is the code that I wrote for
LibraryServiceImpl
/*
* LibraryServiceImpl.java
*
* Created on 30 August 2008, 15:51
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package org.silica.library.test.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.silica.library.test.client.Library;
import org.silica.library.test.client.LibraryService;
import com.google.gwt.user.client.rpc.InvocationException;
/**
*
* @author Administrator
*/
public class LibraryServiceImpl extends RemoteServiceServlet
implements LibraryService {
private static final String QUERY = "select * from authors
where id=2";
public Library getAuthor() {
DataSource ds = getDataSource();
Library author = null;
try {
Connection conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement(QUERY);
ResultSet results = ps.executeQuery();
while (results.next()) {
author = new Library();
author.setId(results.getInt("id"));
author.setFname(results.getString("firstname"));
author.setLname(results.getString("lastname"));
}
conn.close();
return author;
} catch (SQLException e){
throw new InvocationException("Exeption querying database",e);
}
}
private static DataSource getDataSource(){
InitialContext ctx;
try {
ctx = new InitialContext();
return
(DataSource)ctx.lookup("java:comp/env/jdbc/MyDataSource");
} catch (NamingException e) {
throw new InvocationException("Exception getting
datasoure",e);
}
}
}
The following is my client side code
1)
/*
* Library.java
*/
package org.silica.library.test.client;
import com.google.gwt.user.client.rpc.IsSerializable;
public class Library implements IsSerializable {
private int id;
private String fname;
private String lname;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getFname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getLname() {
return lname;
}
}
2)
/*
* LibraryService.java
*
* Created on 30 August 2008, 15:51
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package org.silica.library.test.client;
import com.google.gwt.user.client.rpc.RemoteService;
public interface LibraryService extends RemoteService{
public Library getAuthor();
}
3)
/*
* LibraryServiceAsync.java
*
*/
package org.silica.library.test.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface LibraryServiceAsync {
public void getAuthor(AsyncCallback callback);
}
Based on this code how can I be able to display the id, firstname and
lastname fields of the db simply to atleast show that I can get stuff
from a db and render it?
On Sep 1, 2:18 am, "Jim Freeze" <[EMAIL PROTECTED]> wrote:
> On Sun, Aug 31, 2008 at 3:43 AM, Abel B <[EMAIL PROTECTED]> wrote:
>
> > Hi, I am new to both the java language and gwt. I have been reading on
> > the language for a few months and I have a grasp on some of the most
> > important concepts.
>
> > I have been having a hard time rendering data on a browser aftre
> > making server side calls to a mysql db. I have read about using remote
> > procedure calls on the server side and then using the entry point
> > class to render the info retrieved from the application service.
>
> > Is there anyone who knows where I can get a step by step guide on
> > working with CRUD functions and rendering them on the browser using
> > gwt. I'm at a loss on what im doing wrong.
>
> I use RequestBuilder and format the response data with json.
> It's actually very straightforward.
>
> Where exactly are you having problems?
> Can you show us some code that isn't working?
>
> --
> Jim Freeze
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---