Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection grdCON = null;
- Statement grdST = null;
- ResultSet grdRS=null;
- String grdDB = "jdbc:mysql://localhost:3306/graduate-work-db";
- String user = "root";
- String password = "paswrd";
- String msgDB=null;
- try{
- Class.forName("com.mysql.jdbc.Driver");
- grdCON = DriverManager.getConnection(grdDB,user,password);
- grdST = grdCON.createStatement();
- grdRS = grdST.executeQuery("Select name from users where id=5;");
- if(grdRS.next()){
- msgDB = grdRS.toString();
- }
- } catch (SQLException | ClassNotFoundException excp){
- msgDB = excp.getMessage();
- } finally {
- try {
- if (grdRS!=null){
- grdRS.close();
- }
- if (grdST !=null){
- grdST.close();
- }
- if (grdCON!=null){
- grdCON.close();
- }
- }catch (SQLException excp){
- msgDB = excp.getMessage();
- }
- }
- request.getRequestDispatcher("/index.jsp").forward(request, response);
- <%@ page contentType="text/html;charset=UTF-8" language="java" %>
- <html>
- <head>
- <title>Test</title>
- </head>
- <body>
- Test
- <br>
- <br>
- <h1>${msgDB}</h1>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement