关于Servlet中JDBC数据库调用的问题,请高手解决

any_cold 2002-05-11 05:12:09
我在写一个Servlet,其中用JDBC调用mysql数据库,但是我运行的时候,在IE中显示
message: Servlet invoker is currently unavailable
description: The requested service (Servlet invoker is currently unavailable) is not currently available
这样的错误.
程序代码如下:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.text.DateFormat;

public class ShowEmployees extends HttpServlet
{
Connection dbConn = null;

/**
* Establishes a connection to the database.
*/
public void init() throws ServletException
{
String jdbcDriver = "org.gjt.mm.mysql.Driver";
String dbURL = "jdbc:mysql://localhost:3306/phonebook?user=root;password=";

try
{
Class.forName(jdbcDriver).newInstance(); //load driver
dbConn = DriverManager.getConnection(dbURL); //connect
}
catch (ClassNotFoundException e)
{
throw new UnavailableException("JDBC driver not found:" +
jdbcDriver);
}
catch (SQLException e)
{
throw new UnavailableException("Unable to connect to: " +
dbURL);
}
catch (Exception e)
{
throw new UnavailableException("Error: " + e);
}
}


public void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException
{
response.setContentType("text/html");

PrintWriter out = response.getWriter();

try
{
//join EMPLOYEE and DEPARTMENT tables to get all data
String sql = "select * from EMPLOYEE,DEPARTMENT";


Statement stmt = dbConn.createStatement();
ResultSet rs = stmt.executeQuery(sql);

out.println("<HTML>");
out.println("<HEAD><TITLE>Show Employees</TITLE></HEAD>");
out.println("<BODY>");
out.println("<TABLE BORDER=\"1\" CELLPADDING=\"3\">");
out.println("<TR>");
out.println("<TH>Name</TH>");
out.println("<TH>Department</TH>");
out.println("<TH>Phone</TH>");
out.println("<TH>Email</TH>");
out.println("<TH>Hire Date</TH>");
out.println("</TR>");

while (rs.next())
{
out.println("<TR>");

out.println("<TD>" + rs.getString("LAST_NAME") + ", " +
rs.getString("FIRST_NAME") + "</TD>");
out.println("<TD>" + rs.getString("NAME") + "</TD>");
out.println("<TD>" + rs.getString("PHONE") + "</TD>");
out.println("<TD>" + rs.getString("EMAIL") + "</TD>");

java.sql.Date hireDate = rs.getDate("HIRE_DATE");
DateFormat longDate = DateFormat.getDateInstance(
DateFormat.LONG);
out.println("<TD>" + longDate.format(hireDate) +
"</TD>");

out.println("</TR>");
}

out.println("</TABLE>");
out.println("</BODY></HTML>");

rs.close();
stmt.close();
}
catch (SQLException e)
{
out.println("<H2>Database currently unavailable.</H2>");
}

out.close();
}
}
我不知道这是什么原因,请各位指教.
...全文
49 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
osfig 2002-05-11
这好像与servlet本身无关,是配置环境的问题吧
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告