1、环境:myeclipse9.0tomcat6.0MySQL5.52、在myeclipse里面创建了一个web项目,然后新建了一个JSP文件,代码如下
1、环境:myeclipse9.0 tomcat6.0 MySQL5.5
2、在myeclipse里面创建了一个web项目,然后新建了一个JSP文件,代码如下
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
数据连接池DataSource ds=null;
java.sql.Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try{
ctx=new InitialContext();
Context Envctx = (Context) ctx.lookup("java:comp/env");
ds=(DataSource)Envctx.lookup("dataSource");
con=ds.getConnection();
stmt=con.createStatement();
String sql="select * from student";
rs=stmt.executeQuery(sql);
}catch(SQLException se)
{
se.printStackTrace();
}catch(NamingException ne)
{
ne.printStackTrace();
}
%>
cellPadding="1" cellPadding="0" width=50%>
学号姓名年龄while (rs.next())
{
%>
}
rs.close();
stmt.close();
con.close();
%>
3、tomcat下server.xml的配置如下:
maxActive="100" maxIdle="30" maxWait="10000" userName="root"
password="123456" driverClassName="org.jgt.mm.mysql.Driver"
url="jdbc:mysql://localhost/test"/>
使用MySQL创建的数据库为student.源文件为:
use test;
drop table student;
create table student(sno varchar(10),sname varchar(10),sage int);
insert into student("1001","AAA",21);
4、网上查有人说在tomcat下的web.xml中加入以下配置:
DB Connection
dataSource
javax.sql.DataSource
Container
但是我加过之后还是不行。。。。
哪位大侠肯帮帮我,好几天了,不知道哪里有错。。。
5错误信息:
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
展开