Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. <%@ page import="java.sql.*"%>
  2. <html>
  3. <head>
  4. <title>JDBC Connection example</title>
  5. </head>
  6.  
  7. <body>
  8. <h1>JDBC Connection example</h1>
  9.  
  10. <%
  11. String db = request.getParameter("db");
  12. String user = db; // assumes database name is the same as username
  13. try {
  14. java.sql.Connection con;
  15. Class.forName("org.gjt.mm.mysql.Driver");
  16. con = DriverManager.getConnection("jdbc:mysql://localhost/"+db, user, "xxxxxxx");
  17. out.println (db+ "database successfully opened.");
  18. }
  19. catch(SQLException e) {
  20. out.println("SQLException caught: " +e.getMessage());
  21. }
  22. %>
  23.  
  24. </body>
  25. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement