D
D
DunkanMaklaut2020-06-26 15:14:03
Java
DunkanMaklaut, 2020-06-26 15:14:03

I can't display information from the database to the JSP servlet?

I want to display a table from the MS SQL database into a jsp page, I output it using an array list, I fill it through a separate class with methods, but it is not filled in the servlet (I checked it through the debugger, it stops on the line with the driver connection), respectively, the page is empty , and to the console application through main without any problems...

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;
}


Servlet:
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);
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question