JSP连接数据库报错:
exception
javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.sql_005ftest1_jsp._jspService(sql_005ftest1_jsp.java:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
root cause
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:148)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:69)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:141)
org.apache.jsp.sql_005ftest1_jsp._jspService(sql_005ftest1_jsp.java:50)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
请大家执教一下
------解决方案--------------------
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
驱动没有
------解决方案--------------------
你的驱动还没有加载进去
------解决方案--------------------
邮件已发,注意查收,貌似驱动是3个文件,我刚才说错了
------解决方案--------------------
换个写法试试
<%
try{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
}
catch(ClassNotFoundException e)
{
out.print( "类找不到! "+e);
}
try{
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs ";
//pubs 为你的数据库的
String user= "sa ";
String password= "6261046 ";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql= "select job_id,job_desc from jobs ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {
您的第一个字段内容为: <%=rs.getString(1)%> <br/>
您的第二个字段内容为: <%=rs.getString(2)%> <br/>
}
out.print( "数据库操作成功,恭喜你 ");
rs.close();
stmt.close();
conn.close();
}
catch(SQLException el)
{
out.print( "SQL异常! "+el);
}
%>
------解决方案--------------------
晕,建议你用eclipse来写吧。这是你的环境没有配好,造成驱动包找不到.
------解决方案--------------------
把JDBC的驱动加在TOMCAT/COMMON/LIB下也可以。