All Downloads are FREE. Search and download functionalities are using the official Maven repository.

holmos.webtest.junitextentions.parameters.database.ConnectionInfo Maven / Gradle / Ivy

There is a newer version: 1.0.2u10
Show newest version
package holmos.webtest.junitextentions.parameters.database;

import holmos.webtest.junitextentions.annotations.DataBase;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
 * @author 吴银龙([email protected])
 * */
public class ConnectionInfo {
	private String catalog;
	private String schema;
	private String url;
	private String username;
	private String password;
	private String driver;
	private String connectionName;
	private Connection connection;
	public ConnectionInfo(DataBase dataBase){
		this.catalog=dataBase.catalog();
		this.schema=dataBase.schema();
		this.url=dataBase.url();
		this.username=dataBase.username();
		this.password=dataBase.password();
		this.driver=dataBase.driver();
		this.connectionName=dataBase.connectionName();
	}
	public String getCatalog() {
		return catalog;
	}

	public void setCatalog(String catalog) {
		this.catalog = catalog;
	}

	public String getSchema() {
		return schema;
	}

	public void setSchema(String schema) {
		this.schema = schema;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getConnectionName() {
		return connectionName;
	}

	public void setConnectionName(String connectionName) {
		this.connectionName = connectionName;
	}

	public void setConnection(Connection connection) {
		this.connection = connection;
	}

	public Connection getConnection(){
		if(null!=connection){
			try {
				if(!connection.isClosed())
					return connection;
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		/***************需要增加数据库连接语句*/
		try {
			Class.forName(driver);
			connection=DriverManager.getConnection(url, username, password);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return connection;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy