2016-01-04 140 views
1
<%@page import="java.sql.SQLException"%> 
<%@page import="java.io.IOException"%> 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
<%@ page import="java.text.SimpleDateFormat" %> 
<%@page import="java.sql.ResultSet"%> 
<%@page import="java.sql.Statement"%> 
<%@page import="java.sql.DriverManager"%> 
<%@page import="java.sql.Connection"%> 



<table> 
<% 
try 
{ 

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 


Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433/dbname","username","password"); 

Statement statement = con.createStatement() ; 

ResultSet resultset = statement.executeQuery("select FileName_WO_Ext from dbo.ALLOTMENT WHERE STR_TO_DATE(DATE, '%d/%m/%Y') >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) AND STR_TO_DATE(DATE, '%d/%m/%Y') <= DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY);") ; 


while(resultset.next()) 
{ 
String datee =resultset.getString("FileName_WO_Ext "); 
out.println(datee); 
} 
} 
catch(SQLException ex){ 
System.out.println("exception--"+ex); 

} 

%> 
</table> 

一個例外,這是我的代碼我收到eroor是我在連接到SQL Server

HTTP狀態500 - 發生異常處理JSP頁面/second.jsp在線路164

類型異常報告

消息時發生異常處理JSP頁/second.jsp在管線164

描述服務器遇到一個內部錯誤預實現這一要求後將其排出。

例外

org.apache.jasper.JasperException: An exception occurred processing JSP page /second.jsp at line 164 

161: <% 

162: try 

163: { 

164: Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 

165: 

166: 

167: Connection con = 
DriverManager.getConnection("jdbc:sqlserver://localhost:1433/CubeHomeTrans","sa","softex"); 


Stacktrace: 
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:575) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:462) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
root cause 

javax.servlet.ServletException: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver 
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916) 
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845) 
    org.apache.jsp.second_jsp._jspService(second_jsp.java:292) 
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
root cause 

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver 
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1856) 
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1705) 
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126) 
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63) 
    java.lang.Class.forName0(Native Method) 
    java.lang.Class.forName(Unknown Source) 
    org.apache.jsp.second_jsp._jspService(second_jsp.java:252) 
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.67 logs. 
+1

確保JDBC驅動程序的lib文件夾 – Ramanlfc

+0

我有lib文件夾中的SQL JDBC驅動程序jar文件 – halfe

+0

那麼這LIB未裝載 – afzalex

回答

-1

我設法清除錯誤

  • 我從lib刪除jar文件後,
  • 並再次添加它到build path,並在該lib文件夾WEB-INF,
  • 最後,我再次運行程序。