Advertisement
stevennathaniel

MYSQL : Test Koneksi Menggunakan JSP

Jul 28th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. <%@ page import = "java.sql.Connection" %>
  2. <%@ page import = "java.sql.DriverManager" %>
  3. <%@ page import = "java.sql.SQLException" %>
  4. <%@ page import = "java.util.Properties" %>
  5.  
  6. <html>
  7.  
  8. <!--- test koneksi ke server MySQL menggunakan bahasa pemrograman JSP.
  9.  
  10.         Sebelumnya copy paste terlebih dahulu driver MYSQL J Connector
  11.         ke path C:\apache-tomcat-8.0.23\lib (Windows).
  12.  
  13.                 Referensi: http://stackoverflow.com/questions/5556664/how-to-fix-no-suitable-driver-found-for-jdbcmysql-localhost-dbname-error-w
  14.        
  15.             -->
  16.  
  17. <head>
  18. <title>Koneksi Database</title>
  19. </head>
  20.  
  21. <body>
  22.  
  23.  
  24. <%
  25.  
  26. try{
  27.    
  28.     DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  29.    
  30.     Connection koneksi = null;
  31.    
  32.     String url = "jdbc:mysql://localhost:3306/pdam";
  33.    
  34.     String user = "root";
  35.    
  36.     String password = "kucing";
  37.    
  38.     koneksi = DriverManager.getConnection(url,user,password);
  39.    
  40.     if(koneksi != null);
  41.    
  42.     out.println("Berhasil Terkoneksi ke Database");
  43.    
  44.     koneksi.close();
  45.    
  46.    
  47. }catch(Exception ex){
  48.    
  49.     out.println("Gagal Terkoneksi " + ex);
  50.    
  51. }
  52.  
  53.  
  54.  
  55.  
  56. %>
  57.  
  58.  
  59. </body>
  60.  
  61.  
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement