- server.xml
1 2 3 4 5 6 7 8 | <Context docBase="test" path="/test" reloadable="true" source="org.eclipse.jst.jee.server:test"> <Resource name="jdbc/sqlite" auth="Container" type="javax.sql.DataSource" driverClassName="org.sqlite.JDBC" url="jdbc:sqlite:/tmp/test.db" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"/> </Context> |
- WEB-INF/web.xml
1 2 3 4 5 6 7 8 9 | <?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" id="WebApp_ID" version="2.5"> <display-name>test</display-name> <resource-ref> <res-ref-name>jdbc/sqlite</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app> |
- jsp
1 2 3 4 5 6 7 8 9 10 11 12 | <%@ page language="java" contentType="text/html; charset=Shift_JIS" pageEncoding="Shift_JIS"%><%@ page import="java.sql.*,javax.naming.*,javax.sql.*,java.util.*,java.text.*,java.net.*" %> <% InitialContext ic = new InitialContext(); DataSource ds=(DataSource)ic.lookup("java:comp/env/jdbc/sqlite"); Connection conn=ds.getConnection(); PreparedStatement ps=conn.prepareStatement("select datetime('now','localtime')"); ps.execute(); ResultSet rs=ps.getResultSet(); while(rs.next()){ out.println(rs.getString(1)); } %> |
- 結果
1 | 2013-04-18 17:01:20 |