Oracle 开发篇+Java通过共享模式访问Oracle数据库

  • 标签:共享服务器进程、shared server process
  • 释义:shared server process是Oracle的一种数据库连接技术,类似的还有专用模式和DRCP

★ 数据库配置

alter system set shared_server_sessions=1 scope=spfile;
alter system set max_shared_servers=1 scope=spfile;
alter system set shared_servers=1 scope=spfile;
alter system set max_dispatchers=1 scope=spfile;
alter system set dispatchers='(PROTOCOL=TCP)(DISPATCHERS=1)' scope=spfile;

★ Java代码

package PAC_001;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;
public class CLA_oracle {
	public static void main(String args[]) throws SQLException {
		OracleDataSource ods = null;
		Connection conn = null;
		Statement stmt = null;
		ResultSet rset = null;
		ods = new OracleDataSource();
		ods.setURL("jdbc:oracle:thin:@1.1.1.9:1521/prodpdb1:shared");
		ods.setUser("zzt");
		ods.setPassword("zzt");
		conn = ods.getConnection();
		try {
			stmt = conn.createStatement();
			rset = stmt.executeQuery("SELECT count(*) FROM zzt.emp");
			while (rset.next())
				System.out.println(rset.getString(1));
		}
		finally {
			if (rset != null)
				rset.close();
			if (stmt != null)
				stmt.close();
			if (conn != null)
				conn.close();
		}
	}
}


※ 如果您觉得文章写的还不错, 别忘了在文末给作者点个赞哦 ~

你可能感兴趣的:(数据库+Oracle,数据库,共享模式,shared,server)