zoukankan      html  css  js  c++  java
  • Glassfish数据源配置详解

    本文环境:

    Win2003 + myeclipse6.01 + sqlserver2000(sp4) 

    1、 安装glassfish——启动,在管理控制台下配置如下

    首先配置连接池——大家把sqlserver的驱动包放在glassfish安装目录下的lib里。

    接着是配置JNDI(同时选中刚才配置好的连接池)

    2、测试

    常规方法测试1:在servlet中测试代码如下:

    try {

    Context ctx = new InitialContext();

    DataSource ds = (DataSource) ctx.lookup("myds");

    Connection conn = ds.getConnection();

    System.out.println(conn);

    ResultSet rs = conn.createStatement().executeQuery(

    "select * from admin ");

    while (rs.next()) {

    System.out.println(rs.getObject(2));

    System.out.println(rs.getObject(3));

    }

    } catch (Exception e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    常规方法测试2:在servlet中测试代码如下:

    public class HelloWorld extends HttpServlet {

        private @Resource(name="myds") DataSource nt;

        private @Resource(name="welcomeMessage") String welcomeMsg;

        protected void processRequest(HttpServletRequest request, HttpServletResponse response)

                throws ServletException, IOException {

            response.setContentType("text/html;charset=UTF-8");

            System.out.println("OK");

            PrintWriter out = response.getWriter();

            Connection conn = nt.getConnection();  

      }

  • 相关阅读:
    vuebase----3.slot插槽
    vuebase-2.Props的验证组件的深入
    vuebase-1.Props的验证
    组件的加载与keep-alive
    组件传递数据props
    简单的组件
    表单和侦听器
    class和style的绑定
    每次加载更新新的背景图
    vue--计算属性
  • 原文地址:https://www.cnblogs.com/jymz/p/4293551.html
Copyright © 2011-2022 走看看