独角兽企业重金招聘Python工程师标准>>>
<!-- The contents of this file will be loaded for each web application -->1.将tomcat的conf/目录下的context.xml 修改成如下的操作<Context reload="true"><!-- Default set of monitored resources --><WatchedResource>WEB-INF/web.xml</WatchedResource><!-- Uncomment this to disable session persistence across Tomcat restarts --><!--<Manager pathname="" />--><Resourcename = "jdbc/DBSource" type ="javax.sql.DataSource"maxActive = "4"maxIdle="2"username ="root"maxWait ="5000"driverClassName ="com.mysql.jdbc.Driver"password ="admin"url="jdbc:mysql://localhost:3306/person"/><!name --数据源名driverClassName 使用的JDBC驱动程序的完整类名url 数据库username 数据库的用户名password 数据库的密码type 指定该资源的类型,这里为DataSourcemaxActive 可以同时为该连接池分配的活动连接实例的最大数maxIdle: 该连接池中可空间的连接的最大数maxWait 在没有可连接的时候连接池在抛出异常前等待的最大毫米数validationQuery 在连接被返回应用程序前,连接池用来验证连接的sql查询语句--></Context>数据库中调用才有如下方式<!-- Context context = new InitialContext();DataSource ds = (DataSource)context.lookup("java:comp/enc/jdbc/DBSource");Connection conn = ds.getConnection();-->2.将mysql驱动拷贝到tomcat/lib 目录下3.over