- 浏览: 125063 次
- 性别:
- 来自: 北京
最新评论
-
yangtaoxf126.com:
public class SimpleJDBC {
publ ...
oracle的sys用户怎么通过jdbc连接
oracle的sys用户怎么通过jdbc连接
经过GOOGLE 总算知道了如何在JDBC中使用SYSDBA角色连接ORACLE数据库
在DriverManager.getConnection通过Properties 设置连接的defaultRowPrefetch,nternal_logon 等信息。
oracle的sys用户怎么通过jdbc连接
经过GOOGLE 总算知道了如何在JDBC中使用SYSDBA角色连接ORACLE数据库
在DriverManager.getConnection通过Properties 设置连接的defaultRowPrefetch,nternal_logon 等信息。
// -----------------------------------------------------------------------------
// ConnectionOptions.java
// -----------------------------------------------------------------------------
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
/**
* -----------------------------------------------------------------------------
* The following class provides an example of using jdbc to connect to an
* Oracle database using several advanced options. For example, one of the most
* used option is connecting to a database as SYSDBA. The following table
* contains
*
* Connection Properties Recognized by Oracle jdbc Drivers
* -------------------------------------------------------
* Name Short Name Type Description
* ------------------- ---------- -------- -----------------------------------
* user n/a String The user name for logging into the
* database.
* password n/a String The password for logging into the
* database.
* database server String The connect string for the database.
* internal_logon n/a String A role, such as SYSDBA or SYSOPER,
* that allows you to log on as SYS.
* defaultRowPrefetch prefetch String (containing integer value)
* The default number of rows to
* prefetch from the server.
* (default value is "10")
* remarksReporting remarks String (containing boolean value)
* "true" if getTables() and
* getColumns() should report
* TABLE_REMARKS; equivalent to using
* setRemarksReporting().
* (default value is "false")
* defaultBatchValue batchvalue String (containing integer value)
* The default batch value that triggers
* an execution request.
* (default value is "10")
* includeSynonyms synonyms String (containing boolean value)
* "true" to include column information
* from predefined "synonym" SQL
* entities when you execute a
* DataBaseMetaData getColumns() call;
* equivalent to connection
* setIncludeSynonyms() call.
* (default value is "false")
*
* -----------------------------------------------------------------------------
*/
public class ConnectionOptions {
final static String driverClass = "oracle.jdbc.driver.OracleDriver";
final static String connectionURL = "jdbc:oracle:thin:@localhost:1521:TRUESRC";
final static String userID = "scott";
final static String userPassword = "tiger";
Connection con = null;
/**
* Construct a QueryExample object. This constructor will create an Oracle
* database connection.
*/
public ConnectionOptions() {
Properties conProps = new Properties();
conProps.put("user", userID);
conProps.put("password", userPassword);
conProps.put("defaultRowPrefetch", "15");
conProps.put("internal_logon", "sysdba");
try {
System.out.print(" Loading jdbc Driver -> " + driverClass + "n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "n");
this.con = DriverManager.getConnection(connectionURL, conProps);
System.out.print(" Connected as -> " + userID + "n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
} catch (InstantiationException e) {
e.printStackTrace();
System.exit(1);
} catch (IllegalAccessException e) {
e.printStackTrace();
System.exit(1);
} catch (SQLException e) {
e.printStackTrace();
System.exit(1);
}
}
/**
* Method to check which database user we are logged in as
*/
public void performUserQuery() {
Statement stmt = null;
ResultSet rset = null;
String queryString = "SELECT user, TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI:SS') " +
"FROM dual";
try {
System.out.print(" Creating Statementn");
stmt = con.createStatement ();
System.out.print(" Opening ResultsSetn");
rset = stmt.executeQuery(queryString);
rset.next();
System.out.println(" Database User -> " + rset.getString(1));
System.out.println(" Date / Time -> " + rset.getString(2));
System.out.println();
System.out.print(" Closing ResultSetn");
rset.close();
System.out.print(" Closing Statementn");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* Close down Oracle connection.
*/
public void closeConnection() {
try {
System.out.print(" Closing Connectionn");
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
*/
public static void main(String[] args) {
ConnectionOptions co = new ConnectionOptions();
co.performUserQuery();
co.closeConnection();
}
}
经过GOOGLE 总算知道了如何在JDBC中使用SYSDBA角色连接ORACLE数据库
在DriverManager.getConnection通过Properties 设置连接的defaultRowPrefetch,nternal_logon 等信息。
oracle的sys用户怎么通过jdbc连接
经过GOOGLE 总算知道了如何在JDBC中使用SYSDBA角色连接ORACLE数据库
在DriverManager.getConnection通过Properties 设置连接的defaultRowPrefetch,nternal_logon 等信息。
// -----------------------------------------------------------------------------
// ConnectionOptions.java
// -----------------------------------------------------------------------------
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
/**
* -----------------------------------------------------------------------------
* The following class provides an example of using jdbc to connect to an
* Oracle database using several advanced options. For example, one of the most
* used option is connecting to a database as SYSDBA. The following table
* contains
*
* Connection Properties Recognized by Oracle jdbc Drivers
* -------------------------------------------------------
* Name Short Name Type Description
* ------------------- ---------- -------- -----------------------------------
* user n/a String The user name for logging into the
* database.
* password n/a String The password for logging into the
* database.
* database server String The connect string for the database.
* internal_logon n/a String A role, such as SYSDBA or SYSOPER,
* that allows you to log on as SYS.
* defaultRowPrefetch prefetch String (containing integer value)
* The default number of rows to
* prefetch from the server.
* (default value is "10")
* remarksReporting remarks String (containing boolean value)
* "true" if getTables() and
* getColumns() should report
* TABLE_REMARKS; equivalent to using
* setRemarksReporting().
* (default value is "false")
* defaultBatchValue batchvalue String (containing integer value)
* The default batch value that triggers
* an execution request.
* (default value is "10")
* includeSynonyms synonyms String (containing boolean value)
* "true" to include column information
* from predefined "synonym" SQL
* entities when you execute a
* DataBaseMetaData getColumns() call;
* equivalent to connection
* setIncludeSynonyms() call.
* (default value is "false")
*
* -----------------------------------------------------------------------------
*/
public class ConnectionOptions {
final static String driverClass = "oracle.jdbc.driver.OracleDriver";
final static String connectionURL = "jdbc:oracle:thin:@localhost:1521:TRUESRC";
final static String userID = "scott";
final static String userPassword = "tiger";
Connection con = null;
/**
* Construct a QueryExample object. This constructor will create an Oracle
* database connection.
*/
public ConnectionOptions() {
Properties conProps = new Properties();
conProps.put("user", userID);
conProps.put("password", userPassword);
conProps.put("defaultRowPrefetch", "15");
conProps.put("internal_logon", "sysdba");
try {
System.out.print(" Loading jdbc Driver -> " + driverClass + "n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "n");
this.con = DriverManager.getConnection(connectionURL, conProps);
System.out.print(" Connected as -> " + userID + "n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
} catch (InstantiationException e) {
e.printStackTrace();
System.exit(1);
} catch (IllegalAccessException e) {
e.printStackTrace();
System.exit(1);
} catch (SQLException e) {
e.printStackTrace();
System.exit(1);
}
}
/**
* Method to check which database user we are logged in as
*/
public void performUserQuery() {
Statement stmt = null;
ResultSet rset = null;
String queryString = "SELECT user, TO_CHAR(sysdate, 'DD-MON-YYYY HH24:MI:SS') " +
"FROM dual";
try {
System.out.print(" Creating Statementn");
stmt = con.createStatement ();
System.out.print(" Opening ResultsSetn");
rset = stmt.executeQuery(queryString);
rset.next();
System.out.println(" Database User -> " + rset.getString(1));
System.out.println(" Date / Time -> " + rset.getString(2));
System.out.println();
System.out.print(" Closing ResultSetn");
rset.close();
System.out.print(" Closing Statementn");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* Close down Oracle connection.
*/
public void closeConnection() {
try {
System.out.print(" Closing Connectionn");
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
*/
public static void main(String[] args) {
ConnectionOptions co = new ConnectionOptions();
co.performUserQuery();
co.closeConnection();
}
}
评论
1 楼
yangtaoxf126.com
2011-07-14
public class SimpleJDBC {
public static void main(String args[]) {
try{
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Class.forName("oracle.jdbc.driver.OracleDriver");
Properties props= new Properties();
props.put("user","SYS");
props.put("password","wwww");
props.put("internal_logon","sysdba");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl",props);
Statement stmt=conn.createStatement();
stmt.addBatch("grant select on sys.dba_pending_transactions to sys_0000000623 ");
stmt.addBatch("grant select on sys.pending_trans$ to sys_0000000623 ");
stmt.addBatch("grant select on sys.dba_2pc_pending to sys_0000000623 ");
stmt.addBatch("grant execute on sys.dbms_system to sys_0000000623 ");
stmt.executeBatch();
ResultSet rset=stmt.executeQuery("select username from x$kzsrt");
while(rset.next()){
System.out.println("username========= "+rset.getString(1));
}
rset=stmt.executeQuery("select * from dba_tab_privs where grantee = 'SYS_0000000623'");
while(rset.next()){
System.out.println("username========= "+rset.getString(3));
}
}catch(SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
public static void main(String args[]) {
try{
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Class.forName("oracle.jdbc.driver.OracleDriver");
Properties props= new Properties();
props.put("user","SYS");
props.put("password","wwww");
props.put("internal_logon","sysdba");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl",props);
Statement stmt=conn.createStatement();
stmt.addBatch("grant select on sys.dba_pending_transactions to sys_0000000623 ");
stmt.addBatch("grant select on sys.pending_trans$ to sys_0000000623 ");
stmt.addBatch("grant select on sys.dba_2pc_pending to sys_0000000623 ");
stmt.addBatch("grant execute on sys.dbms_system to sys_0000000623 ");
stmt.executeBatch();
ResultSet rset=stmt.executeQuery("select username from x$kzsrt");
while(rset.next()){
System.out.println("username========= "+rset.getString(1));
}
rset=stmt.executeQuery("select * from dba_tab_privs where grantee = 'SYS_0000000623'");
while(rset.next()){
System.out.println("username========= "+rset.getString(3));
}
}catch(SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
发表评论
-
[分享]SQL列转行
2009-09-13 14:15 3433在做一些视图,报表或者查询的时候,列转行是必须要做的,甚至有多 ... -
行列转换等经典SQL语句
2009-09-10 18:22 6821.--行列转换 原表: 姓名 科目 成绩 ... -
oracle 创建数据库
2009-09-06 14:58 0oracle 管理分级 是根据 用户名来的。 上一级是sys, ... -
oracle 创建 sequence
2009-09-06 14:55 1638create sequence emp_sequence ... -
SQL Server中Case 的不同用法
2009-08-09 17:13 1411CASE 可能是 SQL 中被误用最多的关键字之一。虽然你可能 ... -
sqlserver使用SQL 把查询的结果连接起来
2009-08-09 17:11 983使用SQL变量 把查询的结果连接起来 Declare @tm ... -
MySQL存储过程例子,包含事务,输出参数,嵌套调用,游标,循环等等
2009-08-09 17:00 1137drop procedure if exists pro_re ... -
如何在Sql Server 2000中用一条语句实现树的查询
2009-08-09 16:59 1648以公司的网站栏目表为例,表结构(表名:Subject)如下: ... -
sql server日期比较、日期查询常用语句(转)
2009-08-09 16:58 3850sql server日期比较、日期 ...
相关推荐
连接数据库,快速实现对oracle的连接
NULL 博文链接:https://rogerfederer.iteye.com/blog/1815171
Class.forName ("oracle.jdbc.driver.OracleDriver");//确保该驱动正确加载 Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@ip address:1521:ORA1", "scott", "tiger"); Statement stmt = ...
要使一个客户端机器能连接oracle数据库,需要在客户端机器上安装oracle的客户端软件,唯一的例外就是java连接数据库的时候,可以用jdbc thin模式,不用装oracle的客户端软件。加入你在机器上装了oracle数据库,就不...
作者通过总结各自多年的软件开发和教学培训经验,与大家分享了掌握Oracle SQL所独有的丰富功能的技巧所在,内容涵盖SQL执行、联结、集合、分析函数、子句、事务处理等多个方面。读者可以学习到以下几个方面的技巧:...
测试atomikos spring activemq jta oracle 为了最大限度地恢复和关闭/重启能力,强烈建议您使用以下 init 依赖项配置 Spring 配置: 使事务管理器依赖于您所有的 JDBC 和 JMS 连接工厂:这可确保在关闭期间事务管理...
MySQL提供了一系列安全措施,如用户账户管理、访问权限控制、SSL/TLS加密连接、审计日志等功能,确保数据的安全性和合规性。同时,MySQL附带了一系列管理工具,如MySQL Server、MySQL Workbench、MySQL Shell等,...
- If connected as sys with sysdba role, Types node displays built in data-types (e.g. BLOB, DATE, DECIMAL, etc.) If clicked on, will only see "create or replace". 1.4 Creating and Modifying Objects -...
#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver #hibernate.connection.username ora #hibernate.connection.password ora #hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl...
支持通过 JDBC 和 ODBC 连接超过 29 种的数据库。 DB2 H2 Microsoft Access Oracle SQLite DBASE HSQLDB Mimer SQL Paradox SQL Anywhere Derby Informix MongoDB Pervasive SQL Azure Filemaker Ingres MS SQL ...
*** ACTION NAME:() 2009-04-01 09:31:00.762*** MODULE NAME:(JDBC Thin Client) 2009-04-01 09:31:00.762*** SERVICE NAME:(SYS$USERS) 2009-04-01 09:31:00.762*** SESSION ID:(145.9) 2009-04-01 09:31:00.762**...
* 5.identity 使用SQL Server和MySQL的自增字段,这个方法不能放到Oracle中,Oracle不支持自增字段,要设定sequence(MySQL和SQL Server中很常用)。等同于JPA中的IDENTITY * 例:@GeneratedValue(generator = ...