搞了4个小时,完全没用,特来求助大家!
package les8;import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;public class CreateDBServlet extends HttpServlet{
private String url;
private String user;
private String password;
    public void init() throws ServletException {
String driverClass=getInitParameter("driverClass");
url=getInitParameter("url");
user=getInitParameter("user");
password=getInitParameter("password");
try {
        Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
        throw new UnavailableException("加载数据库驱动失败");
        }
    }    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
Connection conn=null;
Statement stmt=null;
try{
     conn=DriverManager.getConnection(url, user, password);
     stmt=conn.createStatement();
     stmt.executeUpdate("create database bookstore");
     stmt.executeUpdate("use bookstore");
     stmt.executeUpdate("create table bookinfo(id INT not null primary key," +
     "title VARCHAR(50) not null,"+
     "author VARCHAR(50) not null,"+
     "bookconcern VARCHAR(100) not null,"+
     "publish_date DATE not null,"+
     "price FLOAT(4,2) not null,"+
     "amount SMALLINT,re VARCHAR(200))ENGINE=InnoDB");
     stmt.addBatch("insert into bookinfo values(1,'Java 从入门到精通','张三','张三出版社'," +
     "'2004-6-1',34.00,35,null)");
     stmt.addBatch("insert into bookinfo values(2,'Jsp深入编程','李四','李四出版社'," +
     "'2004-10-1',56.00,20,null)");
     stmt.addBatch("insert into bookinfo values(3,'J2EE高级编程','王五','王五出版社'," +
     "'2005-3-1',78.00,10,null)");
     stmt.executeBatch();
    
     PrintWriter out=resp.getWriter();
     out.println("success!");
     out.close();
}catch(SQLException se){
se.printStackTrace();
}finally{
if(stmt!=null){
try{
stmt.close();
}catch(SQLException se){
se.printStackTrace();
}
stmt=null;
}
if(conn!=null){
try{
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
conn=null;
}
}
    }


}web.xml 如下:<?xml version="1.0" encoding="gb2312"?><web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5"> <servlet>
      <servlet-name>CreateDBServlet</servlet-name>
      <servlet-class>les8.CreateDBServlet</servlet-class>
 
<init-param>
    <param-name>driverClass</param-name>
    <param-value>com.mysql.jdbc.Driver</param-value>
</init-param> <init-param>
    <param-name>url</param-name>
    <param-value>jdbc:mysql://localhost:3306/mysql</param-value>
</init-param> <init-param>
    <param-name>user</param-name>
    <param-value>root</param-value>
</init-param> <init-param>
    <param-name>password</param-name>
    <param-value>root</param-value>
</init-param>
</servlet>    <servlet-mapping>
        <servlet-name>CreateDBServlet</servlet-name>
        <url-pattern>/createdb</url-pattern>
    </servlet-mapping>
</web-app>访问http://localhost/ch08/createdbHTTP Status 404 - Servlet CreateDBServlet is not available--------------------------------------------------------------------------------type Status reportmessage Servlet CreateDBServlet is not availabledescription The requested resource (Servlet CreateDBServlet is not available) is not available.

解决方案 »

  1.   

    访问的url不存在!http://localhost:端口/工程名/createdb
      

  2.   

    没找到你的CreateDBServlet确认一下<servlet-class>les8.CreateDBServlet</servlet-class>
    路径对不对?
      

  3.   

    tomcat
        apache-tomcat-6.0.18
             webapps
                 ch08
                    WEB-INF
                          classes
                                les8
                                        CreateDBServlet.class
                          lib
                                jstl.jar
                                standard.jar
                          web.xml
      

  4.   

    刚解决掉,我用oracle数据库遇到的,复制classes12.jar到WEB-INF\lib