dataSourcetest.jsp 873 B

123456789101112131415161718192021222324252627282930313233
  1. <%--
  2. Created by IntelliJ IDEA.
  3. User: LENOVO
  4. Date: 2022/4/13
  5. Time: 11:53
  6. To change this template use File | Settings | File Templates.
  7. --%>
  8. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  9. <%@ page language="java" pageEncoding="GB2312" %>
  10. <%@ page import="java.sql.*,javax.sql.*,javax.naming.*" %>
  11. <html>
  12. <head>
  13. <title>配置数据源</title>
  14. </head>
  15. <body>
  16. <%
  17. Connection conn=null;
  18. //String url="jdbc:mysql://localhost:3306/edu";
  19. //String user="root";
  20. //String password="123456";
  21. try{
  22. InitialContext ctx = new InitialContext();
  23. DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/edu");
  24. conn = ds.getConnection();
  25. if(conn != null){
  26. out.println("数据源 jdbc/edu 配置正确!");
  27. }
  28. }catch(Exception ex){
  29. out.println("数据库驱动加载出现错误!"+ex);
  30. }
  31. %>
  32. </body>
  33. </html>