函数,它返回连接变量

huangapple 未分类评论56阅读模式
英文:

Function which returns connection variable

问题

在我的Java应用程序中,我有这样的代码:

    private static OracleDataSource oracleDatasource;

    public static OracleConnection getConnection() throws SQLException 
	{
		final OracleConnection conn = (OracleConnection) oracleDatasource.getConnection("user", "password");
		return conn;
	}

我想要在Postgres JDBC中编写一个等效的函数。我知道我可以使用这行代码来定义数据源:

    private static PGSimpleDataSource postgresDatasource;

但是我应该如何定义并返回类似Oracle中的连接变量呢?

英文:

In my Java application I have such code:

private static OracleDataSource oracleDatasource;

public static OracleConnection getConnection() throws SQLException 
{
	final OracleConnection conn = (OracleConnection) oracleDatasource.getConnection("user", "password");
	return conn;
}

I would like to write equivalent of such function in Postgres JDBC. I know that I could use this line

private static PGSimpleDataSource postgresDatasource;

to define data source. But how can I define and return connection variable like it was in Oracle?

huangapple
  • 本文由 发表于 2020年7月27日 18:40:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/63113616.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定