⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydatasource.java

📁 各种数据保存:字符型
💻 JAVA
字号:
package cn.itcast.jdbc.datasource;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import javax.sql.DataSource;

public class MyDataSource implements DataSource {
	private static String url = "jdbc:mysql://localhost:3306/test?user=root&password=root";

	private static String user = "root";

	private static String password = "root";

	private List connections = new Vector();

	private static int maxCount = 200;

	private int currntCount = 0;

	public MyDataSource() {
		for (int i = 0; i < 10; i++) {
			try {
				connections.add(this.createConnection());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public Connection getConnection() throws SQLException {
		Connection conn = null;
		if (this.connections.size() > 0)
			conn = (Connection) this.connections.remove(0);
		if (conn == null && this.currntCount < maxCount)
			conn = this.createConnection();
		return conn;
	}

	private Connection createConnection() throws SQLException {
		Connection realConn = DriverManager.getConnection(url, user, password);
		MyConnection conn = new MyConnection(this.connections, realConn);
		this.currntCount++;
		return conn;
	}

	public Connection getConnection(String username, String password)
			throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public PrintWriter getLogWriter() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public int getLoginTimeout() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	public void setLogWriter(PrintWriter out) throws SQLException {
		// TODO Auto-generated method stub

	}

	public void setLoginTimeout(int seconds) throws SQLException {
		// TODO Auto-generated method stub

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -