Не могу вывести информацию с БД в сервлет JSP
Хочу вывести таблицу из бд MS SQL в jsp-страницу, вывожу с помощью array list, его же заполняю через отдельный класс с методами, но в сервлете он не заполняется(через отладчик проверял, стопорится на строке с подключением драйвера), соответственно страница пустая выходит, а в консольное приложение через main без проблем...
это класс через который я заполняю array
public static ArrayList<Employer> select() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
String url = "****";
String login = "**** ";
String password = "*****";
ArrayList<Employer> employers = new ArrayList<Employer>();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").getDeclaredConstructor().newInstance();
try {
Connection connection = getConnection(url, login, password);
// System.out.println("Connection succesfull!");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select r.rsrc_id,r.rsrc_name,r.rsrc_short_name,r.rsrc_title_name,u.udf_text from rsrc r\n" +
"inner join UDFVALUE u\n" +
"on r.rsrc_id=u.fk_id\n" +
"and u.udf_type_id=42\n" +
"where r.active_flag='Y'\n" +
"and r.timesheet_flag='Y'");
while (resultSet.next()) {
Employer employer = new Employer(resultSet.getInt(1), resultSet.getString(2), resultSet.getString(3),
resultSet.getString(4), resultSet.getString(5));
employers.add(employer);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return employers;
}
Сервлет:
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@WebServlet("/")
public class IndexServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int a = 0;
ArrayList<Employer> employers = null;
try {
employers = EmployerDB.select();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
request.setAttribute("employers", employers);
getServletContext().getRequestDispatcher("/out.jsp").forward(request, response);
}
}