[jboss-user] [JNDI and Naming] - jndi naming, @javax.annotation.Resource(mappedName versus name)
Martin Vejmelka
do-not-reply at jboss.com
Wed Nov 24 11:38:02 EST 2010
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]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20101124/9de73661/attachment-0001.html
More information about the jboss-user
mailing list