当前位置: 代码迷 >> Java Web开发 >> 用sevrlet编撰的创建库的程序,出错(HTTP Status 500),请高手执教
  详细解决方案

用sevrlet编撰的创建库的程序,出错(HTTP Status 500),请高手执教

热度:117   发布时间:2016-04-17 15:16:51.0
用sevrlet编写的创建库的程序,出错(HTTP Status 500),请高手执教
import   java.io.*;
import   java.sql.*;

import   javax.servlet.*;
import   javax.servlet.http.*;

public   class   CreateDB   extends   HttpServlet   {

public   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)
throws   ServletException,   IOException  
{

    String   driverClass=getInitParameter( "driverClass ");
    url=getInitParameter( "driverClass ");  
    user=getInitParameter( "user ");
    password=getInitParameter( "password ");  

    try  
    {  
    Class.forName(driverClass);  
    }
    catch(ClassNotFoundException   ce)  
    {  
    throw   new   UnavailableException( "加载数据库驱动失败! ");  
    }
   
//--------------------------------------    
Connection   conn=null;
Statement   stmt=null;
try
{
conn=DriverManager.getConnection(url,   user,   password);
stmt=conn.createStatement();
stmt.executeUpdate( "create   database   bookstore ");
stmt.execute( "use   bookstore ");
stmt.execute( "create   tableBookInfo( "  
    +   "id   INT   not   null   primary   key "  
    + "title   VERCHAR(50)not   null "
    +   "author   VACHAR(50)   not   null, "
    +   "bookconcernVARCHAR(100)   not   null "
    +   "publish_date   not   null "  
    +   "price   FAOT(4,2)   not   null, "
    +   "amount   SMALLINT, "
    +   "remarkVARCHAR(200))ENGINE=InnoDB) "  
    );  
stmt.addBatch( "insert   into   values(1, 'ddd ', '张 ', 'eee ', '2004-6-1 ',34.00,35,null) ");
stmt.addBatch( "insert   into   values(2, 'fff ', '李 ', 'rrr ', '2005-3-1 ') ");
stmt.addBatch( "insert   into   values(3, ' 'ggg ', '王 ', 'yyy ', '2006-10-1 ',78.00,10,null) ");
stmt.executeBatch();
   
PrintWriter   out=response.getWriter();
out.println( "seccess! ");
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;
}
}
}

//     public   void   init()   throws   ServletException  
//     {
//     String   driverClass=getInitParameter( "driverClass ");
  相关解决方案