新建 <wlp_home>\usr\shared\resources\mysql,把mysql的jar包扔进去
在server.xml中可以通过${shared.resource.dir}指代<wlp_home>\usr\shared\resources\ 见http://www-01.ibm.com/support/knowledgecenter/api/content/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_setup.htmlserver.xml中的各种ref(各种egg hurt的配置)
http://www-01.ibm.com/support/knowledgecenter/api/content/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_setup_reftags.html 最终我的看起来很晦涩的配置如下:servlet-3.0 jdbc-4.0
这里有各种数据连接的参考配置:
http://www-01.ibm.com/support/knowledgecenter/api/content/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_dep_configuring_ds.html修改HelloServlet.java的代码如下
package test;import java.io.IOException;import java.io.PrintWriter;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.annotation.Resource;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.sql.DataSource;@WebServlet("/HelloServlet")public class HelloServlet extends HttpServlet { @Resource(name = "jdbc/blogDS") private DataSource ds; private Connection con; @Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("Hello World Liberty Profile
\n"); try { con = ds.getConnection(); Statement stmt = null; stmt = con.createStatement(); // create a table stmt.executeUpdate("create table cities (name varchar(50) not null primary key, population int, county varchar(30))"); // insert a test record stmt.executeUpdate("insert into cities values ('myHomeCity', 106769, 'myHomeCounty')"); // select a record ResultSet result = stmt .executeQuery("select county from cities where name='myHomeCity'"); result.next(); // display the county information for the city. out.println("The county for myHomeCity is " + result.getString(1)); // drop the table to clean up and to be able to rerun the test. stmt.executeUpdate("drop table cities"); } catch (SQLException e) { e.printStackTrace(); } finally { if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } } }}
这段java代码来自于http://www-01.ibm.com/support/knowledgecenter/api/content/SSEQTP_8.5.5/com.ibm.websphere.wlp.doc/ae/twlp_dep_jdbc.html, 看起来没有关闭statement和resultset(有内存泄漏?) 同样使用如下命令编译即可 javac -cp C:\IBM\was855nalp\dev\api\spec\com.ibm.ws.javaee.servlet.3.0_1.0.1.jar HelloServlet.java