Advertisement
oke_google

Spring Hibernate Connection

Feb 3rd, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package com.rsia.madura.config;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5.  
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.*;
  8. import javax.servlet.http.*;
  9.  
  10. import java.sql.*;
  11.  
  12. @WebServlet("/TestConnection")
  13. public class ConnectionConfig extends HttpServlet{
  14.     private static final long serialVersionUID = 1L;
  15.  
  16.    
  17.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  18.         String user = "postgres";
  19.         String pass = "postgre";
  20.         String jdbcURL = "jdbc:postgresql://localhost:5432/rsia_madura";
  21.        
  22.         String driverDB = "org.postgresql.Driver";
  23.        
  24.         try {
  25.             PrintWriter out = response.getWriter();
  26.            
  27.             out.println("Try to connect " + jdbcURL);
  28.            
  29.             Class.forName(driverDB);
  30.            
  31.             Connection conn = DriverManager.getConnection(jdbcURL, user, pass);
  32.            
  33.             out.println("Succes");
  34.            
  35.             conn.close();
  36.         }catch(Exception e) {
  37.             e.printStackTrace();
  38.             throw new ServletException(e);
  39.         }
  40.     }
  41.    
  42.    
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement