Guest User

Untitled

a guest
Nov 14th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  3. "http://www.w3.org/TR/html4/loose.dtd">
  4.  
  5. <%@ page import="java.sql.*" %>
  6. <%@ page import="java.io.*" %>
  7.  
  8. <html>
  9. <head>
  10. <title>Connection with mysql database</title>
  11. </head>
  12. <body>
  13. <h1>Connection status </h1>
  14. <%
  15. try {
  16.  
  17. String connectionURL = "jdbc:mysql://localhost/db1";
  18. Connection connection = null;
  19. Class.forName("com.mysql.jdbc.Driver").newInstance();
  20.  
  21. connection = DriverManager.getConnection(connectionURL, "root", "root");
  22.  
  23.  
  24. if(!connection.isClosed())
  25. %>
  26. <font size="+3" color="green">
  27. <%
  28. out.println("Successfully connected to " + "MySQL server using TCP/IP...");
  29. connection.close();
  30. }
  31. catch(Exception ex){
  32. %>
  33. </font>
  34. <font size="+3" color="red">
  35. <%
  36. out.println("Unable to connect to database.");
  37. }
  38. %>
  39. </font>
  40. </body>
  41. </html>
Add Comment
Please, Sign In to add comment