[JSP ] unreported exception java.sql.SQLExc …
最近嘗試用Sevlet來處理網頁的東西,
可是有個問題一直找不出來...
上網爬文說要處理例外性錯誤,可是我也有處理了...
但是還是有問題,不知道我的寫法是否正確?
錯誤訊息:
Login.java:12: unreported exception java.sql.SQLException; must be caught or
declared to be thrown
Conn = DBConnect.getConnection();
^
Login.java:36: unreported exception java.sql.SQLException; must be caught or
declared to be thrown
if(MyRs!=null) MyRs.close();
^
Login.java:37: unreported exception java.sql.SQLException; must be caught or
declared to be thrown
if(prepStmt!=null) prepStmt.close();
^
Login.java:38: unreported exception java.sql.SQLException; must be caught or
declared to be thrown
Conn.close();
^
4 errors
我的程式碼如下:
package com.posm;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.posm.LDAP;
import com.posm.DBConnect;
import java.sql.*;
public class Login extends HttpServlet {
public void service (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException{
Connection Conn = null;
Conn = DBConnect.getConnection();
ResultSet MyRs = null;
PreparedStatement prepStmt = null;
LDAP Auth = new LDAP();
String account = request.getParameter("account");
String password = request.getParameter("password");
String result = Auth.LdapAuth(account,password)[0];
try{
if("0".equals(result)){
prepStmt = Conn.prepareStatement("Select Account From Account
Where Account = ?");
prepStmt.setString(1,account);
MyRs = prepStmt.executeQuery();
if(MyRs!=null&&MyRs.next()){
response.sendRedirect("/POSM/Main.html");
}else{
response.sendRedirect("/POSM/Index.html");
}
}else{
response.sendRedirect("/POSM/Index.html");
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(MyRs!=null) MyRs.close();
if(prepStmt!=null) prepStmt.close();
Conn.close();
}
}
}
--
請勿拍打、餵食!
http://www.wretch.cc/album/etchen
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.211.33.46
※ 編輯: etchen 來自: 218.211.33.46 (04/29 16:15)
推
04/29 16:15, , 1F
04/29 16:15, 1F
推
04/29 16:38, , 2F
04/29 16:38, 2F
→
04/29 16:40, , 3F
04/29 16:40, 3F
→
04/29 16:49, , 4F
04/29 16:49, 4F