Martin Vejmelka [http://community.jboss.org/people/wayman] created the 
discussion

"jndi naming, @javax.annotation.Resource(mappedName versus name)"

To view the discussion, visit: http://community.jboss.org/message/572824#572824

--------------------------------------------------------------
public class jg extends HttpServlet {
 
    @Resource(name = "java:/comp/env/jdbc/sisds")
    DataSource sistestds;
 
    protected void processRequest(HttpServletRequest request, 
HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        try {
            response.setContentType("text/html;charset=UTF-8");
 
            // obtaining connection
            Connection conn = sistestds.getConnection();
 
            // preparing and executing statement
            PreparedStatement st = conn.prepareStatement("SELECT ip FROM jail");
            st.execute();
 
            // printing resultset
            ResultSet rs = st.getResultSet();
            while (rs.next()) {
                out.println(rs.getString("ip"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(jg.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            out.close();
        }
    }
 Dear JBoss community members,

I am really complete newbie to JBoss technologies. The very first thing a have 
tried was simple servlet with JDBC DataSource Resource injection... Something 
like...

public class jg extends HttpServlet {

    @Resource(name = "java:/comp/env/jdbc/sisds")
    DataSource sistestds;

    protected void processRequest(HttpServletRequest request, 
HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        try {
            response.setContentType("text/html;charset=UTF-8");

            // obtaining connection
            Connection conn = sistestds.getConnection();

            // preparing and executing statement
            PreparedStatement st = conn.prepareStatement("SELECT ip FROM jail");
            st.execute();

            // printing resultset
            ResultSet rs = st.getResultSet();
            while (rs.next()) {
                out.println(rs.getString("ip"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(jg.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            out.close();
        }
    }

... (the method gets called from appropriate get/post... etc. calls)...
 
I have simple table containing list of some virtual servers (jails) and want to 
list their IP addresses. This snippet of code would work in GlassFish, ... but 
JBoss reports that mappedName should be used... in the @Resource injection...
 
In fact... it functions with the mappedName... but I want my application to be 
as portable as possible and I'd like to avoid using platform specific things 
like mappedName....
 
Should mention that I am using JBoss AS 5.0.1 GA on Linux...
 
Any help is welcome...
 
Martin Vejmelka
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/572824#572824]

Start a new discussion in JNDI and Naming at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to