Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @WebServlet(urlPatterns = "/day")
- protected String resQ = null;
- GregorianCalendar calendar = new GregorianCalendar();
- int dayID = calendar.get(Calendar.DAY_OF_MONTH); //
- private static final String URL = "jdbc:mysql://localhost:3306/DataBase";
- private static final String USER = "root";
- private static final String PASSWORD = "root";
- private Connection currentConnect;
- public void initDisconnection() throws Exception {
- currentConnect.close();
- }
- public void initConnection() throws Exception {
- Class.forName("com.mysql.jdbc.Driver");
- currentConnect = DriverManager.getConnection(URL, USER, PASSWORD);
- }
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws
- ServletException, IOException {
- try {
- initConnection();
- Statement statement = currentConnect.createStatement();
- String query = ("select * from db_predict.db_predict WHERE ID =" + dayID);
- ResultSet resultQuery = statement.executeQuery(query);
- while (resultQuery.next()) {
- resQ = resultQuery.getString("Text");
- }
- initDisconnection();
- } catch (Exception e) {
- e.printStackTrace();
- }
- PrintWriter out = response.getWriter();
- out.println("<h1>" + resQ + "</h1>"); //Вывод на экран текста
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement