Hi, 

We are trying to work a simple EJB 3 application. Our goal is to post a 
stateless bean and acces to it from a web application.

We are developing it with eclipse. Here is the program structure:
-A java application that contains two interfaces and the bean (also a metainf) 
to implement the stateless bean.
-A web application 2.4 (we had tried also with 2.5).

We deploye the bean as a jar in the jboss, and it seems to recognize it. But 
when we try to acces with the web app (via servlet) we got an 
java.nullPointerException.

Ejb Code:


  | import java.sql.ResultSet;
  | import java.sql.SQLException;
  | import javax.ejb.Remote;
  | 
  | 
  | /**
  |  * This is the business interface for Carp enterprise bean.
  |  */
  | @Remote
  | public interface EjbRemote {
  | 
  |     boolean doStatement(String queryName) throws SQLException;
  | 
  |     ResultSet doQuery(String query) throws SQLException;
  |     
  |     void printQuery(String query);
  | }
  | 


  | import java.sql.ResultSet;
  | import java.sql.SQLException;
  | import javax.ejb.Local;
  | @Local
  | public interface EjbLocal {
  | 
  |     boolean doStatement(String queryName) throws SQLException;
  | 
  |     ResultSet doQuery(String query) throws SQLException;
  |     
  |     void printQuery(String query);
  | }
  | 


  | import javax.annotation.Resource;
  | import javax.ejb.Stateless;
  | import javax.sql.DataSource;
  | import java.sql.Statement;
  | import java.sql.Connection;
  | import java.sql.ResultSet;
  | import java.sql.SQLException;
  | 
  | @Stateless
  | public class EjbBean implements EjbLocal, EjbRemote {
  | 
  |     @Resource(mappedName = "TACWDS") DataSource TACWDS;
  |     
  |     public EjbBean() {
  | 
  |     }
  |     
  |     public boolean doStatement(String query) {
  |         //TODO implement doStatement
  |         return false;
  |     }
  | 
  |     public final ResultSet doQuery(String query) throws SQLException {
  |             System.out.println("Esecuzione query : " + query);
  |         Connection conn = TACWDS.getConnection();
  |         Statement stm = conn.createStatement();
  |         return stm.executeQuery(query);
  |     }
  |     
  |     public final void printQuery(String query) {
  |             System.out.println("Esecuzione query : " + query);
  |     }
  | }
  | 

Servlet Code:


  | 
  | public class appServlet extends HttpServlet {
  |     @EJB EjbLocal sless;
  | 
  |     public void service(HttpServletRequest req, HttpServletResponse resp) 
  |             throws ServletException, IOException{           
  | 
  |         resp.setContentType("text/html");
  |         PrintWriter out = resp.getWriter();
  |         //sless.printQuery("SELECT * FROM FOO");
  |         
  |         System.out.println("sless state: "+sless);
  |     }
  | }
  | 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117092#4117092

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117092
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to