Advertisement
Guest User

Untitled

a guest
Jul 9th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. Connection grdCON = null;
  2. Statement grdST = null;
  3. ResultSet grdRS=null;
  4. String grdDB = "jdbc:mysql://localhost:3306/graduate-work-db";
  5. String user = "root";
  6. String password = "paswrd";
  7. String msgDB=null;
  8. try{
  9. Class.forName("com.mysql.jdbc.Driver");
  10. grdCON = DriverManager.getConnection(grdDB,user,password);
  11. grdST = grdCON.createStatement();
  12. grdRS = grdST.executeQuery("Select name from users where id=5;");
  13. if(grdRS.next()){
  14. msgDB = grdRS.toString();
  15. }
  16. } catch (SQLException | ClassNotFoundException excp){
  17. msgDB = excp.getMessage();
  18. } finally {
  19. try {
  20. if (grdRS!=null){
  21. grdRS.close();
  22. }
  23. if (grdST !=null){
  24. grdST.close();
  25. }
  26. if (grdCON!=null){
  27. grdCON.close();
  28. }
  29.  
  30. }catch (SQLException excp){
  31. msgDB = excp.getMessage();
  32. }
  33. }
  34. request.getRequestDispatcher("/index.jsp").forward(request, response);
  35.  
  36. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  37. <html>
  38. <head>
  39. <title>Test</title>
  40. </head>
  41. <body>
  42. Test
  43. <br>
  44. <br>
  45. <h1>${msgDB}</h1>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement