JSP连接到SQL Server 2000出现的问题,不知道如何解决!帮帮偶!谢谢!

努力偷懒 2005-11-14 11:34:03
下面的JSP代码没问题,可以正常显示出来:-----------------------
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<html>
<body>
以下是从Ms SQL Server2000数据库读取的数据:<hr>
<table border=1>
<tr><td>id</td><td>书名</td><td>出版社 </td><td>价格</td></tr>

<%
//注意黑体字
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/BookDB","root","2230901");
Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookdb","sa","lijuheng");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from books");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+rst.getString("Id")+"</td>");
out.println("<td>"+rst.getString("Name")+"</td>");
out.println("<td>"+rst.getString("title")+"</td>");
out.println("<td>"+rst.getFloat("price")+"</td>");
out.println("</tr>");
}
//关闭连接
rst.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>

而下面的连接却出现了问题,不知道错在哪,我是从书上抄下来的:--------------

<!--首先导入一些必要的packages-->
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<!--告诉编译器使用SQL包-->
<%@ page import="java.sql.*"%>
//我的
//<%@ page import="com.microsoft.*"%>
<!--设置中文输出-->
<%@ page contentType="text/html; charset=GB2312" %>

<html>
<head>
<title>DbJsp.jsp</title>
</head>
<body>
<%
//以try开始
try
{

Connection con;
Statement stmt;
ResultSet rs;

//加载驱动程序,下面的代码为加载MySQL驱动程序(旧)
//Class.forName("com.mysql.jdbc.Driver");
//加载SQL Server的驱动程序:(我)
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

//注册MySQL驱动程序(旧)
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//注册SQL Server驱动程序(我)
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());

//用适当的驱动程序连接到数据库--useUnicode=true&characterEncoding=GB2312:读取数据时采用的编码
//String dbUrl = "jdbc:mysql://localhost:3306/BookDB?useUnicode=true&characterEncoding=GB2312";
//jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookdb","sa","lijuheng"
String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433/DatabaseName=BookDB?useUnicode=true&characterEncoding=GB2312";
//旧的
//String dbUser="dbuser";
//我的
String dbUser="sa";
//旧的
//String dbPwd="1234";
//我的
String dbPwd="lijuheng";

//建立数据库连接
con = java.sql.DriverManager.getConnection(dbUrl,dbUser,dbPwd);
//创建一个JDBC声明
stmt = con.createStatement();
//增加新记录
stmt.executeUpdate("INSERT INTO books (id,name,title,price) VALUES ('999','Tom','Tomcat Bible',44.5)");
//查询记录
rs = stmt.executeQuery("SELECT id,name,title,price from books");
//输出查询结果
out.println("<table border=1 width=400>");
while (rs.next())
{
String col1 = rs.getString(1);
String col2 = rs.getString(2);
String col3 = rs.getString(3);
float col4 = rs.getFloat(4);
//打印所显示的数据
out.println("<tr><td>"+col1+"</td><td>"+col2+"</td><td>"+col3+"</td><td>"+col4+"</td></tr>");
}
out.println("</table>");

//删除新增加的记录
stmt.executeUpdate("DELETE FROM books WHERE id='999'");

//关闭数据库连结
rs.close();
stmt.close();
con.close();

}

//捕获错误信息
catch (Exception e) {out.println(e.getMessage());}
%>
</body>
</html>


提示的错误:------------------------------------
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

No Java compiler was found to compile the generated source for the JSP.
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:128)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:413)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.
...全文
288 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
努力偷懒 2006-04-04
  • 打赏
  • 举报
回复
帮帮偶啦!
努力偷懒 2005-11-17
  • 打赏
  • 举报
回复
我把msbase,mssqlserver,msutil都拷贝到tomcat的common下的lib里面去了!为何我引用这个会提示错误的啊?
xunxm 2005-11-14
  • 打赏
  • 举报
回复
关于数据操作的部分最好放JAVABEAN中
shkirin 2005-11-14
  • 打赏
  • 举报
回复
This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
If using an alternate Java compiler, please check its installation and access path.
先用他给的方法解决一下
看看环境有没有配置好
Tiky_0720 2005-11-14
  • 打赏
  • 举报
回复
环境没配置好,因为你的JSP文件都还没编译~
huangyq_002 2005-11-14
  • 打赏
  • 举报
回复
<!--<%@ page import="com.microsoft.*"%>-->这样的注释经常不行 对于象include这样的注释俺经常< %@ page import="com.microsoft.*"%>注释!
努力偷懒 2005-11-14
  • 打赏
  • 举报
回复
晕死啊!
<!--<%@ page import="com.microsoft.*"%>-->有这一句在就提示那种错误,
<%@ page import="com.microsoft.*"%>有这一句在也提示出错!
努力偷懒 2005-11-14
  • 打赏
  • 举报
回复
Tomcat的那个common/lib里面已经有了那个tools.jar文件了!
努力偷懒 2005-11-14
  • 打赏
  • 举报
回复
我这里有2段代码的哦!第一段代码执行没问题的哦!第二段代码却出现那个问题。如果是我的环境没配置好,为何第一段可以正常运行啊?

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧