JSP连接数据库问题。
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /check.jsp at line 20
17: String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";
18: String username="sa";
19: String userpwd="sa";
20: Connection conn=DriverManager.getConnection(url, username, userpwd);
21: Statement stmt=conn.createStatement();
22: String sql="select * from Table_1 where account= '"+name+"'";
23: ResultSet rs=stmt.executeQuery(sql);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:456)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.check_jsp._jspService(check_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.check_jsp._jspService(check_jsp.java:82)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.20 logs.
代码如下。
<%
String name=request.getParameter("text1");
String pwd =request.getParameter("pwd1");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";
String username="sa";
String userpwd="sa";
Connection conn=DriverManager.getConnection(url, username, userpwd);
Statement stmt=conn.createStatement();
String sql="select * from Table_1 where account= '"+name+"'";
ResultSet rs=stmt.executeQuery(sql);
rs.first();
out.print(rs.getObject("account"));
%>
刚刚自学,打击真不小……
[解决办法]
[解决办法]
你是2005的数据库吧。那你的url应该用:jdbc:sqlserver://localhost:1433;DatabaseName=student
不是:
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student
吧。
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html