webshere 中配置oracle 数据源 视频

Posted on 2010-02-03 14:48 ㄨ.壞小駭 阅读(215) 评论(0)  编辑  收藏 所属分类: javaEE 视频

视频下载地址:http://code.google.com/p/seasjalor/


以下是  测试数据源是否配置成功 代码 是一个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 自动生成 catch 块
            e.printStackTrace();
        }


    }


}



ㄨ.壞小駭  技术只是工具....
----------------------------!@#$%JAVAEE技术群:2987841--------------------------

只有注册用户登录后才能发表评论。


网站导航:
 

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

Copyright © ㄨ.壞小駭