******异常信息如题,是在MyEclipse中报出的,配置文件是按照tomcat5.0的配置信息配置的,当然,之前使用过.1X的tomcat也报同样的错误,然后以为是我的版本有问题,后改为5.0的,但是依旧报同样的错误.
目前在jsp文件中调试时,已经能够获取到链接" Connection conn = ds.getConnection();
out.println("get the conn!---->"+conn); "(具体代码见详细信息)但是,在MyEcilpse中调试时却报标题异常,请各位多帮忙,在下在线等待,有劳了 .!!!!!!!!!!~~~~~~~~~~~~~~
********tomcat server.xml中的配置 :
<Context path="/TestOTA" docBase="TestOTA" debug="1" reloadable="true" crossContext="true">
<Resource name="jdbc/OracleDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="hailong" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mysql?autoReconnect=true"/>
</Context>
********* Web.xml文件中配置
<resource-ref>
<description>MySQL Test App</description>
<res-ref-name>jdbc/OracleDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref >
*********开发环境:
MyEclipse 5.0GA
Tomcat4.1.27/4.1.30/5.5
JDK:1.4.2/5.0
DB MySQL5.0**********myeclipse中代码:
initCtx = new InitialContext();
Context envContext =
(Context)initCtx.lookup("java:/comp/env");
ds = (DataSource) envContext.lookup("jdbc/OracleDB");
conn = ds.getConnection();**************jsp文件调试代码:
<%@ page language="java" %>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<%
DataSource ds = null;
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
//Context lookup
ds = (DataSource)envCtx.lookup("jdbc/OracleDB");
if(ds!=null)
{
out.println("Find DataSource!");
out.println("<br>");
Connection conn = ds.getConnection();
out.println("get the conn!---->"+conn);
java.sql.Statement stmt=conn.createStatement();
ResultSet rst=stmt.executeQuery("select * from tabs");
out.println("Success!");
while(rst.next())
{
out.println("TABLE_NAME:"+rst.getString("TABLE_NAME"));
out.println("<br>");
}
}
else
out.println("Can NOT Find DataSource!");
}
catch(Exception ne)
{
out.println(ne);
}
%>
目前在jsp文件中调试时,已经能够获取到链接" Connection conn = ds.getConnection();
out.println("get the conn!---->"+conn); "(具体代码见详细信息)但是,在MyEcilpse中调试时却报标题异常,请各位多帮忙,在下在线等待,有劳了 .!!!!!!!!!!~~~~~~~~~~~~~~
********tomcat server.xml中的配置 :
<Context path="/TestOTA" docBase="TestOTA" debug="1" reloadable="true" crossContext="true">
<Resource name="jdbc/OracleDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="hailong" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mysql?autoReconnect=true"/>
</Context>
********* Web.xml文件中配置
<resource-ref>
<description>MySQL Test App</description>
<res-ref-name>jdbc/OracleDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref >
*********开发环境:
MyEclipse 5.0GA
Tomcat4.1.27/4.1.30/5.5
JDK:1.4.2/5.0
DB MySQL5.0**********myeclipse中代码:
initCtx = new InitialContext();
Context envContext =
(Context)initCtx.lookup("java:/comp/env");
ds = (DataSource) envContext.lookup("jdbc/OracleDB");
conn = ds.getConnection();**************jsp文件调试代码:
<%@ page language="java" %>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<%
DataSource ds = null;
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
//Context lookup
ds = (DataSource)envCtx.lookup("jdbc/OracleDB");
if(ds!=null)
{
out.println("Find DataSource!");
out.println("<br>");
Connection conn = ds.getConnection();
out.println("get the conn!---->"+conn);
java.sql.Statement stmt=conn.createStatement();
ResultSet rst=stmt.executeQuery("select * from tabs");
out.println("Success!");
while(rst.next())
{
out.println("TABLE_NAME:"+rst.getString("TABLE_NAME"));
out.println("<br>");
}
}
else
out.println("Can NOT Find DataSource!");
}
catch(Exception ne)
{
out.println(ne);
}
%>
你用mysql数据库,怎么会写成Oracle?
mysql jdbc驱动包放好位置没?
另外,驱动包没有会报找不到驱动的错误,我已经添加了,所以jsp测试页面才会有结果,才能获取到connection,但是在eclipse中就是获取dataSource的时候,报错,感觉就是配置文件中的信息在eclipse中根本无法获取到,所有参数都是null,可是在jsp中已经获取到了啊 ,所以我非常的郁闷
需要在D:\usr\local\Tomcat5.5\conf\Catalina\localhost下建立soap.xml文件
添加如下代码:
<Context path="/soap" debug="99" reloadable="true" antiJARLocking="true" antiResourceLocking="false">
<ResourceLink name="jdbc/mySQL" global="jdbc/mySQL" type="javax.sql.DataSourcer"/>
</Context>另外在Tomcat5.5\webapps\soap\WEB-INF\web.xml
中添加末尾代码
<servlet-mapping>
<servlet-name>messagerouter</servlet-name>
<url-pattern>/servlet/messagerouter</url-pattern>
</servlet-mapping>
<resource-ref>
<description>MySQL Test App</description>
<res-ref-name>jdbc/mySQL</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>还有就是在
D:\usr\local\Tomcat5.5\conf\server.xml
.............在server.xml文件的host之前添加该段.................
<!-- *********************************wcf begin-->
<DefaultContext reloadable="true" crossContext="true"/>
<Context path="/soap" docBase="soap" debug="1" reloadable="true" crossContext="true">
<Resource name="jdbc/mySQL" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="hailong" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mysql?autoReconnect=true"/>
<!-- ************************wcf add end********************************** -->
<!-- wcf end-->
</Host>
</Engine>
</Service>
</Server>注意:这里使用的都是soap,而非我创建的项目 TestOTA,否则,就无法获取到链接