• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc to get schema user information

 
rajiv jackz
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class JDBCTest {

public static void main(String[] args) throws Exception {
String url = "jdbc:oracle:thin:@192.168.10.133:1521:XE"; //"jdbc:oracle:thin:@localhost:1521:orcl";
String driver = "oracle.jdbc.OracleDriver";
String user = "RAM";
String password = "PWDXS";

try {
Class.forName(driver);

System.out.println("#########################################");

//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url, user, password);

// Get the MetaData
DatabaseMetaData metaData = conn.getMetaData();

// Get driver information
System.out.println("");
System.out.println("#########################################");
System.out.println("# ***DRIVER INFORMATION***");
System.out.println("#");
System.out.println("# Driver Name = " + metaData.getDriverName());
System.out.println("# Driver Version = " + metaData.getDriverVersion());
System.out.println("#");
System.out.println("#########################################");
System.out.println("");
System.out.println("");

// Get database information
System.out.println("#########################################");
System.out.println("# ***DATABASE INFORMATION***");
System.out.println("#");
System.out.println("# Database Product Name = " + metaData.getDatabaseProductName());
System.out.println("# Database Product Version = " + metaData.getDatabaseProductVersion());
System.out.println("#");
System.out.println("#########################################");
System.out.println("");
System.out.println("");

// Get schema information
ResultSet schemas = metaData.getSchemas();
System.out.println("#########################################");
System.out.println("# ***SCHEMA INFORMATION***");
System.out.println("#");
System.out.println("# Schemas:");
while (schemas.next()) {
System.out.println("# " + schemas.getString(1));
}
System.out.println("#########################################");
System.out.println("");
System.out.println("");

// Get table information
System.out.println("Tables");
ResultSet tables = metaData.getTables("", "", "", null);
while (tables.next()) {
System.out.println(tables.getString(3));
}
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
System.out.println("############end#############################");
}
}

How to get user information with this jdbc code.??? provide me solution
 
Goutham Pallipati
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can try DatabaseMetaData.getUserName this will give you user name used in connection. If you need all users in system Not sure what level of previliges you have but can try Oracle specific query "select * from DBA_USERS".

Check this link for more details on DBA_USERS table.

http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_4174.htm
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the code button and indentation and, on this JDBC forum, tick the "disable smilies" box.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic