java连接池

tomcat 中的server.xml

<Context path="/shopping" docBase="/shopping" reloadable="true">

<Resource auth="Container" 

	  name="jdbc/oracle" 

	  type="javax.sql.DataSource" 

	  maxWait="10000" 

	  maxIdle="5" 

	  maxActive="20"

	  username="jn090917" 

	  password="jn090917" 

	  driverClassName="oracle.jdbc.driver.OracleDriver"

	  url="jdbc:oracle:thin:@127.0.0.1:1521:oracle"/>

</Context> 

下面是调用链接池的句子,参考下,希望对你有帮助

public static Connection getConnection(){

		try {

			Context context=new InitialContext();

			DataSource dataSource=(DataSource)context.lookup("java:comp/env/jdbc/oracle");

			conn=dataSource.getConnection();

		} catch (NamingException e) {

			e.printStackTrace();

		} catch (SQLException e) {

			e.printStackTrace();

			JOptionPane.showMessageDialog(null, "连接超时,请查看用户名跟密码是否有错,或Oracle服务端口是否打开!", "提示信息",

				JOptionPane.ERROR_MESSAGE);

		}

		return conn;

		

	}

你可能感兴趣的:(java)