eclipse mysql jndi_Java开发网 - tomcat5配置jndi的问题 (jdbc:comp is not bound in this Context)...

Posted by:returner

Posted on:2004-11-09 22:42

tomcat5配置jndi的问题;斑竹高手们来看看啊,情况紧急!!!!!!!!10万分感谢

这个问题我是搜索出来的,我也遇到了同样的问题,希望高手给于关注:

http://www.cjsdn.net/post/view?bid=7&id=95089&tpg=1&ppg=1&sty=1&age=0#95089

本人的环境是Eclipse2.1.2+tomcat5.0+lomboz+mysql

$tomcat_home$/comm/lib下加入jndi.jar,mysql+jdbc驱动。

在tomcat的Sever.xml中的〈/Engine>前加入以下内容:

factory

org.apache.commons.dbcp.BasicDataSourceFactory

url

jdbc:mysql://localhost:3306/shop

driverclassname

com.mysql.jdbc.Driver

username

root

password

root

maxWait

3000

maxIdle

10

maxActive

100

在Webapps的Web.xml中加入以下内容:

connectDB test

jdbc/hibernate

javax.sql.DataSource

Container

测试代码如下:

package com.yzs.test.hibernate;

import java.io.IOException;

import java.io.PrintWriter;

import javax.naming.*;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.sql.*;

import java.sql.*;

/**

* @author yzs

*

* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

public class testservlet extends HttpServlet {

protected void doGet(

HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

//TODO Method stub generated by Lomboz

Context initctx=null;

Context ctx=null;

DataSource ds=null;

Connection conn=null;

Statement stmt=null;

ResultSet rs=null;

response.setContentType("text/html");

PrintWriter out=response.getWriter();

try {

initctx=new InitialContext();

ctx= (Context) initctx.lookup("jdbc:comp/env");

ds=(DataSource)ctx.lookup("jdbc/hibernate");

if(ds==null) throw new NamingException("no database");

} catch (NamingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

conn=ds.getConnection();

stmt=conn.createStatement();

rs=stmt.executeQuery("select * from brand");

rs.next();

out.println("");

out.println("

out.println("

test jndi");

out.println("");

out.println("

");

out.println(rs.getString("name"));

} catch (SQLException e4) {

// TODO Auto-generated catch block

e4.printStackTrace();

}

}

}

出现了Name jdbc:comp is not bound in this Context的问题,请各位大侠

帮忙看一下问题出在哪里。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值