PUBS データベースの構成を設定する XML コードを用意してあります。その XML をプロジェクトに追加する必要があります。
<?xml version="1.0" encoding="UTF-8"?> <Context> <!-- maxActive: Maximum number of database connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to -1 for no limit. --> <!-- maxIdle: Maximum number of idle database connections to retain in pool. Set to -1 for no limit. See also the DBCP documentation on this and the minEvictableIdleTimeMillis configuration parameter. --> <!-- maxWait: Maximum time to wait for a database connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. --> <!-- username and password: username and password for the connection --> <!-- driverClassName: Class name for the JDBC driver --> <!-- url: The JDBC connection url for connecting to the database --> <Resource name="PUBS" auth="Container" type="javax.sql.DataSource" maxActive="10" maxIdle="10" maxWait="10000" username="SQLServerUserName" password="SQLServerPassword" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://localhost;database=PUBS;" /> </Context>
SQLServerUserName と SQLServerPassword を、SQL Server 認証に必要なユーザー名とパスワードに置き換えます。
web.xml ファイルを変更して、SQL Server データベースに適応させる必要があります。
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>JSPBookDemo</display-name> <servlet> <servlet-name>BookServlet</servlet-name> <servlet-class>com.microfocus.book.BookServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>BookServlet</servlet-name> <url-pattern>/view</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>view</welcome-file> </welcome-file-list> <resource-ref> <description>DB Connection</description> <res-ref-name>PUBS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app>