File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes jdbc to get schema user information Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc to get schema user information" Watch "jdbc to get schema user information" New topic
Author

jdbc to get schema user information

rajiv jackz
Greenhorn

Joined: Jul 12, 2010
Posts: 29
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

Joined: Aug 13, 2008
Posts: 20
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

Joined: Oct 13, 2005
Posts: 40034
    
  28
Please use the code button and indentation and, on this JDBC forum, tick the "disable smilies" box.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc to get schema user information