<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
jndi naming, @javax.annotation.Resource(mappedName versus name)
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/wayman">Martin Vejmelka</a> in <i>JNDI and Naming</i> - <a href="http://community.jboss.org/message/572824#572824">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class jg extends HttpServlet {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">    @Resource(name = "java:/comp/env/jdbc/sisds")</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">    DataSource sistestds;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">    protected void processRequest(HttpServletRequest request, HttpServletResponse response)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            throws ServletException, IOException {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">        PrintWriter out = response.getWriter();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">        try {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            response.setContentType("text/html;charset=UTF-8");</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            // obtaining connection</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            Connection conn = sistestds.getConnection();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            // preparing and executing statement</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            PreparedStatement st = conn.prepareStatement("SELECT ip FROM jail");</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            st.execute();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            // printing resultset</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            ResultSet rs = st.getResultSet();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            while (rs.next()) {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">                out.println(rs.getString("ip"));</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">        } catch (SQLException ex) {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            Logger.getLogger(jg.class.getName()).log(Level.SEVERE, null, ex);</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">        } finally {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">            out.close();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">        }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">    }</div><div> </div>Dear JBoss community members,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><p>public class jg extends HttpServlet {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    @Resource(name = "java:/comp/env/jdbc/sisds")</p><p>    DataSource sistestds;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    protected void processRequest(HttpServletRequest request, HttpServletResponse response)</p><p>            throws ServletException, IOException {</p><p>        PrintWriter out = response.getWriter();</p><p>        try {</p><p>            response.setContentType("text/html;charset=UTF-8");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // obtaining connection</p><p>            Connection conn = sistestds.getConnection();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // preparing and executing statement</p><p>            PreparedStatement st = conn.prepareStatement("SELECT ip FROM jail");</p><p>            st.execute();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>            // printing resultset</p><p>            ResultSet rs = st.getResultSet();</p><p>            while (rs.next()) {</p><p>                out.println(rs.getString("ip"));</p><p>            }</p><p>        } catch (SQLException ex) {</p><p>            Logger.getLogger(jg.class.getName()).log(Level.SEVERE, null, ex);</p><p>        } finally {</p><p>            out.close();</p><p>        }</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>... (the method gets called from appropriate get/post... etc. calls)...</p><div> </div><div>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...</div><div> </div><div>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....</div><div> </div><div>Should mention that I am using JBoss AS 5.0.1 GA on Linux...</div><div> </div><div>Any help is welcome...</div><div> </div><div>Martin Vejmelka</div><div> </div></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/572824#572824">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>