視頻下載地址:http://code.google.com/p/seasjalor/


          以下是  測(cè)試數(shù)據(jù)源是否配置成功 代碼 是一個(gè)servlet

          package com.xh.servlet.test.jdbc;

          import java.io.IOException;
          import java.sql.Connection;
          import java.sql.SQLException;

          import javax.naming.Context;
          import javax.naming.InitialContext;
          import javax.naming.NamingException;
          import javax.servlet.ServletException;
          import javax.servlet.http.HttpServlet;
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;
          import javax.sql.DataSource;

          /**
           * Servlet implementation class TestJndi
           
          */

          public class TestJndi extends HttpServlet {
              
          private static final long serialVersionUID = 1L;

              
          /**
               * 
          @see HttpServlet#HttpServlet()
               
          */

              
          public TestJndi() {
                  
          super();
                  
          // TODO Auto-generated constructor stub
              }


              
          /**
               * 
          @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
               *      response)
               
          */

              
          protected void doGet(HttpServletRequest request,
                      HttpServletResponse response) 
          throws ServletException, IOException {
                  
          this.doPost(request, response);
              }


              
          /**
               * 
          @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
               *      response)
               
          */

              
          protected void doPost(HttpServletRequest request,
                      HttpServletResponse response) 
          throws ServletException, IOException {
                  Context ct 
          = null;
                  
          try {
                      ct 
          = new InitialContext();
                      DataSource ds 
          = (DataSource) ct.lookup("oracle/jdbc");
                      Connection conn 
          = ds.getConnection();
                      System.out.println(
          "----連接:" + conn);
                  }
           catch (NamingException e) {
                      e.printStackTrace();
                  }
           catch (SQLException e) {
                      
          // TODO 自動(dòng)生成 catch 塊
                      e.printStackTrace();
                  }


              }


          }



          ㄨ.壞小駭  技術(shù)只是工具....
          ----------------------------!@#$%JAVAEE技術(shù)群:2987841--------------------------

          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          posts - 2, comments - 0, trackbacks - 0, articles - 0

          Copyright © ㄨ.壞小駭

          主站蜘蛛池模板: 图们市| 盐山县| 宜丰县| 乐清市| 故城县| 临潭县| 河西区| 商南县| 洪雅县| 伊川县| 佳木斯市| 裕民县| 万盛区| 垦利县| 湄潭县| 珲春市| 汝城县| 同德县| 江阴市| 洞口县| 封开县| 轮台县| 屯门区| 临猗县| 霍林郭勒市| 兴义市| 施秉县| 修文县| 张家界市| 华阴市| 营山县| 桂阳县| 商丘市| 上犹县| 岳西县| 灵武市| 东兴市| 罗城| 玉林市| 六安市| 白水县|