81,120
社区成员




- <Resource name="jdbc/mengshan"
- auth="Container"
- type="javax.sql.DataSource"
- maxActive="20"
- maxIdel="10"
- maxWait="1000"
- username="root"
- password=""
- driverClassName="com.mysql.jdbc.Driver"
- url="jdbc:mysql://127.0.0.1:3306/test"
- >
- </Resource>
- <%@ page contentType="text/html; charset=gb2312" %>
- <%@ page import="javax.naming.Context" %>
- <%@ page import="javax.sql.DataSource"%>
- <%@ 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/mengshan"); if(ds!=null) {
- out.println("已经获得DataSource!");
- out.println("<br>");Connection conn = ds.getConnection();
- Statement stmt=conn.createStatement();ResultSet rst=stmt.executeQuery("select * from usertable");
- out.println("以下是从数据库中读取出来的数据");
- while(rst.next()){
- out.println("bookName:"+rst.getString(1));
- out.println("<br>"); }}else out.println("连接失败!"); }
- catch(Exception ne){out.println(ne);}
- %>
-
<Context>
<Resource name="jdbc/mengshan"
auth="Container"
type="javax.sql.DataSource"
maxActive="20"
maxIdel="10"
maxWait="1000"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/test"
>
</Resource>
</Context>
<resource-ref>
<res-ref-name>jdbc/mengshan </res-ref-name>
<res-type>javax.sql.DataSource </res-type>
<res-auth>Container</res-auth>
</resource-ref>
Cannot create JDBC driver of class '' for connect URL 'null'