<%@ page contentType= "text/html; charset=gb2312 " language= "java " errorPage= " " %>
<%@ Page import= "java.sql.* "%>
<html>
<head>
<title> 无标题文档 </title>
</head>
<body>
<%Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver:XING-AE809AD14D;DataaseName=sql ";
String user= "sa ";String password= " ";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql= "select * from student ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){%>
第一个字节内容为: <%=rs.getString(1)%>
第二个字节内容为: <%=rs.getString(2)%>
<%}%>
<%out.print( "数据库连接成功 ");%>
<%rs.close();
stmt.close();
con.close();
%>
</body>
</html>
这个是我看教程的例子的原代码,可是不能成功,显示结果如下:
Error: 500
Location: /myapp/sjk.jsp
Internal Servlet Error:
org.apache.jasper.compiler.ParseException: D:\Tomcat 6.0\jakarta-tomcat\webapps\myapp\sjk.jsp(1,4) Invalid directive
at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:186)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1070)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1035)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1031)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:182)
at org.apache.jasper.servlet.JspServlet.doLoadJSP(JspServlet.java:453)
at org.apache.jasper.servlet.JasperLoader12.loadJSP(JasperLoader12.java:146)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:424)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:152)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:164)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:382)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:387)
at org.apache.tomcat.core.Handler.service(Handler.java:263)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:371)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:786)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:732)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:407)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:595)
到底是什么错了,是不是我的tomcat有问题
------解决方案--------------------
%@ Page import= "java.sql.* "%> page 改小写。笔误???
------解决方案--------------------
String url= "jdbc:microsoft:sqlserver:XING-AE809AD14D;DataaseName=sql "; ??
1433呢
jdbc:microsoft:sqlserver://localhost:1433;
------解决方案--------------------
一定要有密码,把sa用户的密码改为sa试试