Groovy 연속 탱크 사용
/ / 옮 겨 쓰기 설명:http://www.bishen.org
인터넷 에 아직 그루 브 이 로 풀 을 연결 하 는 글 이 없 는 것 같 아 요.
우선 tomcat / lib 에 데이터베이스 드라이브 를 넣 습 니 다.
tomcat / config / content. xml 연결 풀 이름 jdbc / admin 설정
	<Resource name="jdbc/admin" type="javax.sql.DataSource" 
	driverClassName="com.mysql.jdbc.Driver" 
	username="root" 
	password="  " 
	url="jdbc:mysql://localhost:3306/    ?useUnicode=true&characterEncoding=gbk" 
	maxActive="100" 
	maxIdle="30" 
	maxWait="5000" />웹 사이트 의 웹 xml 설정
	 <resource-ref>
	     <description>DB Connection</description>
	     <res-ref-name>jdbc/admin</res-ref-name>
	     <res-type>javax.sql.DataSource</res-type>
	     <res-auth>Container</res-auth>
	 </resource-ref>jsp 예제:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*,javax.sql.DataSource,javax.naming.*"%>
<%
		Context ctx = new InitialContext(); 
		DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/admin"); 
		Connection con = ds.getConnection();
		out.println("data from database:<br>");
		Statement stmt = con.createStatement();
		ResultSet rs = stmt
				.executeQuery("select id,account,username from x_user");
		while (rs.next()) {
			out.println(rs.getInt(1));
			out.println(rs.getString(2));
			out.println(rs.getString(3));
		}
		rs.close();
		stmt.close();
%>Groovy 연결 예시
import groovy.sql.Sql;
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.*;
Context ctx    = new InitialContext();
DataSource ds  = (DataSource) ctx.lookup("java:comp/env/jdbc/admin");
Connection conn= ds.getConnection();
def sql = Sql.newInstance(conn);
def row = sql.eachRow("select id,account,username from x_user"){
	println it.username; 
}
sql.close();
conn.close();이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.