源码:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String user="";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="select * from jobs";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
<%=rs.getString(1)%>
<%=rs.getString(2)%>
<%}%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
错误提示:
org.apache.jasper.JasperException: Exception in JSP: /sql_test.jsp:6 3: <html> 4: <body> 5: <% 6: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 7: String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"; 8: String user=""; 9: String password=""; Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:729)root cause javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774) org.apache.jsp.sql_005ftest_jsp._jspService(sql_005ftest_jsp.java:76) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1386) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232) org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:125) org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63) java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) java.lang.Class.forName0(Native Method) java.lang.Class.forName(Class.java:164) org.apache.jsp.sql_005ftest_jsp._jspService(sql_005ftest_jsp.java:48) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:729)