下面的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 reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPNo 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.
<%@ 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 reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPNo 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.
解决方案 »
- [DWR-STRUTS]
- cvs生成
- 启动server时爆两个Warning
- showModalDialog传值问题
- JSTL里如何输出List里面的Bean中的内容呢
- 关于IE中title显示的问题
- 关于JSP页面多国语的显示问题!
- 刚学JSP不久有点小麻烦。各位大虾来帮帮忙啊。
- No buffer space available (maximum connections reached?)问题如何解决?
- 寻找一个介绍jsp的网站!!!
- 我在http://www.mycodes.net/soft/1566.htm下载到《NTsky留言本v1.2》代码,我看了3天了,还没找到数据库连接池名字是在哪里设置的。请各
- 这样的错误怎么改啦?
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.
先用他给的方法解决一下
看看环境有没有配置好
<!--<%@ page import="com.microsoft.*"%>-->有这一句在就提示那种错误,
<%@ page import="com.microsoft.*"%>有这一句在也提示出错!