Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. @WebServlet(urlPatterns = "/day")
  2.  
  3. protected String resQ = null;
  4.  
  5. GregorianCalendar calendar = new GregorianCalendar();
  6. int dayID = calendar.get(Calendar.DAY_OF_MONTH); //
  7.  
  8. private static final String URL = "jdbc:mysql://localhost:3306/DataBase";
  9. private static final String USER = "root";
  10. private static final String PASSWORD = "root";
  11.  
  12. private Connection currentConnect;
  13.  
  14. public void initDisconnection() throws Exception {
  15. currentConnect.close();
  16. }
  17.  
  18. public void initConnection() throws Exception {
  19. Class.forName("com.mysql.jdbc.Driver");
  20. currentConnect = DriverManager.getConnection(URL, USER, PASSWORD);
  21. }
  22.  
  23. public void doGet(HttpServletRequest request, HttpServletResponse response) throws
  24. ServletException, IOException {
  25. try {
  26. initConnection();
  27.  
  28. Statement statement = currentConnect.createStatement();
  29. String query = ("select * from db_predict.db_predict WHERE ID =" + dayID);
  30. ResultSet resultQuery = statement.executeQuery(query);
  31. while (resultQuery.next()) {
  32. resQ = resultQuery.getString("Text");
  33. }
  34.  
  35. initDisconnection();
  36. } catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39. PrintWriter out = response.getWriter();
  40. out.println("<h1>" + resQ + "</h1>"); //Вывод на экран текста
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement