TXT

Cannot createJDBC driver of class ''for connect...

By Dolores Perkins,2014-11-16 08:49
13 views 0
Cannot createJDBC driver of class ''for connect...

Cannot createJDBC driver of class ''for connect... Cannot create JDBC driver of class

    '' for connect URL 'null' 错误解决方案

sever.xml中加context,若有错误,tomcat不能启动,而单独文件配置时tomcat会忽略

    错误.

单独配置如下:

<Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true"

    crossContext="true">

     <Resource name="jdbc/TestDB" auth="Container"

     type="javax.sql.DataSource" username="root" password="aoe"

     driverClassName="org.gjt.mm.mysql.Driver" url="jdbc:mysql://localhost/websnatch"

     maxActive="8" maxIdle="4"/>

    </Context>

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>test Tomcat</h1>

    <%

    try

    {

    Context initCtx=new InitialContext();

    DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/TestDB");

    Connection conn=ds.getConnection();

    out.println("data from database:<br>");

    Statement stmt=conn.createStatement();

    ResultSet rs =stmt.executeQuery("select id, title, url from news limit 0,10");

    while(rs.next())

    {

    out.println(rs.getInt("id"));

    out.println(rs.getString("title"));

    out.println(rs.getString("url"));

    }

    rs.close();

    stmt.close();

    }

catch(Exception e)

    {

    out.println(e.getMessage());

    }

    %>

    </body>

    </html>

Report this document

For any questions or suggestions please email
cust-service@docsford.com