一,下面是server.xml配置数据库连接池的配置文件
<Resource name ="jdbc/mldn"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="root"
password="mysqladmin"
driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost:3306/mldn"/>
二,接着是web.xml配置文件
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mldn</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
三,下面是通过数据源取得数据库连接的一个JSP
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="javax.naming.*","javax.sql.*","java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'datasource.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String DSNAME="java:comp/env/jdbc/mldn";
Context ctx = new InitialContext();
DataSource ds =(DataSource)ctx.lookup(DSNAME);
Connection conn = ds.getConnection();
%>
<%=conn %>
<%conn.close(); %>
</body>
</html>
在这个JSP中的
DataSource ds =(DataSource)ctx.lookup(DSNAME);
Connection conn = ds.getConnection();
却出现了红色波浪形。还请大家予以指点迷津,这里先表示谢意了!
<Resource name ="jdbc/mldn"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="root"
password="mysqladmin"
driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost:3306/mldn"/>
二,接着是web.xml配置文件
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mldn</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
三,下面是通过数据源取得数据库连接的一个JSP
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="javax.naming.*","javax.sql.*","java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'datasource.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String DSNAME="java:comp/env/jdbc/mldn";
Context ctx = new InitialContext();
DataSource ds =(DataSource)ctx.lookup(DSNAME);
Connection conn = ds.getConnection();
%>
<%=conn %>
<%conn.close(); %>
</body>
</html>
在这个JSP中的
DataSource ds =(DataSource)ctx.lookup(DSNAME);
Connection conn = ds.getConnection();
却出现了红色波浪形。还请大家予以指点迷津,这里先表示谢意了!
没有捕获异常?