jdbc连接池

package Jdbcday02;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import org.apache.commons.dbcp.BasicDataSource;

public class TestConnectionPool {
	public static void main(String[] args) {
		execute();
	}
	public static void execute(){
		BasicDataSource ds=new BasicDataSource();
		ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
		ds.setUrl("jdbc:oracle:thin:@10.12.36.201:1521:xxxxx");
		ds.setPassword("tiger");
		ds.setUsername("scott");
//		ds.setMaxActive(45);
//		System.out.println(ds.getMaxActive());
		try {
			Connection conn =ds.getConnection();
			Statement stmt=conn.createStatement();
			ResultSet rs =
				stmt.executeQuery("select * from emp");
			while(rs.next()){
				System.out.print(rs.getString(1)+"\t");
				System.out.println(rs.getString(2));
			}
			conn.close();
			stmt.close();
		} catch (Exception e) {
		}
	}
}

你可能感兴趣的:(java,apache,oracle,sql,jdbc)