主题:[讨论]大哥哥大姐姐来帮帮忙咯
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet CreateDBServlet threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:595)
root cause
java.lang.NullPointerException
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:164)
org.sunxin.lesson.jsp.bookstore.CreateDBServlet.init(CreateDBServlet.java:22)
javax.servlet.GenericServlet.init(GenericServlet.java:211)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:595)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
这是抱的错!
package org.sunxin.lesson.jsp.bookstore;
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;
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 ce)
{
throw new UnavailableException("加载数据库驱动失败!");
}
}
public 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,remark 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;
}
}
}
}
这是原程序,我从书上抄下来的,没错!
就是连不了库~!!!!!!!!!!!!
为什么????????????????
兄弟姐妹们快来帮帮忙!!
[size=6][/size][color=FF0000][/color]