Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Servlet/JSP/JSF/JavaFX Script  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:javax.naming.NamingException [Re:lijianjun0379]
lijianjun0379





发贴: 5
于 2007-06-03 16:36 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
server.xml如下:

<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_log." suffix=".txt"
timestamp="true"/>

<Context path="/jspdev" docBase="e:\jspdev" debug="0" reloadable="true" crossContext="true">
<Resource name="jdbc/jspdev" auth="Container" type="javax.sql.DateSource"/>

<ResourceParams name="jdbc/jspdev">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDateSourceFactory</value>
</parameter>


<parameter>
<name>driverClassName</name>
<value>net.sourceforge.jtds.jdbc.Driver</value>
</parameter>


<parameter>
<name>url</name>
<value>jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=jspdev</value>
</parameter>


<parameter>
<name>username</name>
<value>sa</value>
</parameter>


<parameter>
<name>password</name>
<value>sa</value>
</parameter>


<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>


<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>


<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>

<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>

<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>

<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>


</ResourceParams>
</Context>

</Host>
--------------------------------------------------------------------
web.xml配置如下;
<resource-ref>
<description>DataSource</description>
<res-ref-name>jdbc/jspdev</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
------------------------------------------------------------------
jsp源代码:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*,javax.sql.DataSource,javax.naming.*"%>
<html>
<head><title>test.jsp</title></head>
<body bgcolor="#ffffff">
<h1>出来吧!</h1>
<%
try
{
Context initCtx=new InitialContext();
DataSource ds=(DataSource)initCtx.lookup("java:comp/env/jdbc/jspdev");
Connection conn=ds.getConnection();
out.println("data from database:<br>");
Statement stmt=conn.createStatement();
ResultSet rs =stmt.executeQuery("select * from user_info");
while(rs.next())
{
out.println(rs.getInt("userid"));
out.println(rs.getString("name"));
out.println(rs.getString("city"));
}
rs.close();
stmt.close();
}

catch(Exception ne)
{
out.println(ne);
}
%>
各位帮帮我看看是什么原因。




请求JAVA学习方向?????

话题树型展开
人气 标题 作者 字数 发贴时间
1963 javax.naming.NamingException lijianjun0379 161 2007-06-03 16:25
1582 Re:javax.naming.NamingException lijianjun0379 3572 2007-06-03 16:36
1577 Re:javax.naming.NamingException snowbug 49 2007-06-11 13:31

reply to postflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923