本文整理汇总了Java中java.sql.DatabaseMetaData.getUserName方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMetaData.getUserName方法的具体用法?Java DatabaseMetaData.getUserName怎么用?Java DatabaseMetaData.getUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.DatabaseMetaData
的用法示例。
在下文中一共展示了DatabaseMetaData.getUserName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testThree
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
* Basic test of DatabaseMetaData functions that access functions
*/
public void testThree() throws Exception {
Connection conn = newConnection();
int updateCount;
try {
TestUtil.testScript(conn, "testrun/hsqldb/TestSelf.txt");
DatabaseMetaData dbmeta = conn.getMetaData();
int txIsolation = dbmeta.getDefaultTransactionIsolation();
String userName = dbmeta.getUserName();
boolean isReadOnly = dbmeta.isReadOnly();
} catch (Exception e) {
assertTrue("unable to prepare or execute DDL", false);
} finally {
conn.close();
}
}
示例2: getDefaultSchema
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Override
public String getDefaultSchema(Connection connection) throws SQLException
{
DatabaseMetaData metaData = connection.getMetaData();
String userName = metaData.getUserName();
ResultSet schemas = metaData.getSchemas();
try
{
while( schemas.next() )
{
String schemaName = schemas.getString("TABLE_SCHEM");
if( userName.equalsIgnoreCase(schemaName) )
{
return schemaName;
}
}
return "public";
}
finally
{
schemas.close();
}
}
示例3: findAllTables
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public List<String> findAllTables(String dataSourceName) throws Exception {
List<String> tablesList = new ArrayList<String>();
Connection conn = null;
ResultSet rs = null;
try {
conn = connectionHelper.getConnection(dataSourceName);
DatabaseMetaData metaData = conn.getMetaData();
String url = metaData.getURL();
String schema = null;
if (url.toLowerCase().contains("oracle")) {
schema = metaData.getUserName();
}
rs = metaData.getTables(null, schema, "%", new String[] { "TABLE" });
while (rs.next()) {
tablesList.add(rs.getString("TABLE_NAME").toLowerCase());
}
return tablesList;
} finally {
if (conn != null) {
conn.close();
}
if (rs != null) {
rs.close();
}
}
}
示例4: getDefaultSchema
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public static String getDefaultSchema(Connection conn) throws SQLException {
String productName = getDatabaseProductName(conn);
if (productName.equals(MYSQL) || productName.equals(SQLSERVER)) {
return conn.getCatalog();
} else {
DatabaseMetaData metaData = conn.getMetaData();
return metaData.getUserName();
}
}
示例5: buildDatabaseTables
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public void buildDatabaseTables(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Connection conn=null;
ResultSet rs = null;
try{
conn=buildConnection(req);
DatabaseMetaData metaData = conn.getMetaData();
String url = metaData.getURL();
String schema = null;
if (url.toLowerCase().contains("oracle")) {
schema = metaData.getUserName();
}
List<Map<String,String>> tables = new ArrayList<Map<String,String>>();
rs = metaData.getTables(null, schema, "%", new String[] { "TABLE","VIEW" });
while (rs.next()) {
Map<String,String> table = new HashMap<String,String>();
table.put("name",rs.getString("TABLE_NAME"));
table.put("type",rs.getString("TABLE_TYPE"));
tables.add(table);
}
writeObjectToJson(resp, tables);
}catch(Exception ex){
throw new ServletException(ex);
}finally{
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeConnection(conn);
}
}
示例6: findTableInfos
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public List<TableInfo> findTableInfos(String dbInfoId) throws Exception {
List<TableInfo> tablesList = new ArrayList<TableInfo>();
DataSource ds = this.getDataSourceByDbInfoId(dbInfoId);
Connection conn = null;
ResultSet rs = null;
try {
conn = DataSourceUtils.getConnection(ds);
DatabaseMetaData metaData = conn.getMetaData();
String url = metaData.getURL();
String schema = null;
if (url.toLowerCase().contains("oracle")) {
String value = Configure.getString("bdf2.default.schema");
if (StringUtils.hasText(value)) {
schema = value;
} else {
schema = metaData.getUserName();
}
}
rs = metaData.getTables(null, schema, "%", new String[] { "TABLE" });
TableInfo tableInfo = null;
while (rs.next()) {
tableInfo = new TableInfo();
tableInfo.setTableName(rs.getString("TABLE_NAME"));
tableInfo.setDbInfoId(dbInfoId);
tablesList.add(tableInfo);
}
return tablesList;
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeConnection(conn);
}
}
示例7: loadDbTables
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@DataProvider
public Collection<TableDef> loadDbTables() throws Exception{
Collection<TableDef> result=new ArrayList<TableDef>();
DataSource ds=this.getJdbcTemplate().getDataSource();
Connection con = DataSourceUtils.getConnection(ds);
Statement stmt = null;
ResultSet rs=null;
try{
DatabaseMetaData metaData = con.getMetaData();
String url=metaData.getURL();
String schema=null;
if(url.toLowerCase().contains("oracle")){
schema=metaData.getUserName();
}
rs = metaData.getTables(null,schema, "%",new String[] { "TABLE" });
while (rs.next()) {
TableDef table=new TableDef();
table.setName(rs.getString("TABLE_NAME"));
table.setPrimaryKeys(loadTablePrimaryKeys(table.getName(),metaData));
result.add(table);
}
}finally{
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(stmt);
JdbcUtils.closeConnection(con);
}
return result;
}
示例8: getDefaultSchemaTables
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public static Map<String, List<String>> getDefaultSchemaTables(Connection conn) throws Exception {
Map<String, List<String>> map = new HashMap<String, List<String>>();
DatabaseMetaData databaseMetaData = conn.getMetaData();
List<String> tables = new ArrayList<String>();
String[] t = { "TABLE" };
String url = databaseMetaData.getURL();
String currentDb = null;
if (url.toLowerCase().contains("oracle")) {
currentDb = databaseMetaData.getUserName();
}
ResultSet rsTable = databaseMetaData.getTables(null, currentDb, "%", t);
String schema = null;
try {
while (rsTable.next()) {
String tableName = rsTable.getString(3);
if (!(tableName.startsWith("BIN$") && tableName.endsWith("==$0"))) {
tables.add(rsTable.getString(3));
if (rsTable.getString(1) != null) {
schema = rsTable.getString(1);
} else if (rsTable.getString(2) != null) {
schema = rsTable.getString(2);
}
}
}
} finally {
DbJdbcUtils.closeResultSet(rsTable);
}
if (schema != null) {
map.put(schema, tables);
} else {
map.put(conn.getCatalog() != null ? conn.getCatalog() : currentDb, tables);
}
return map;
}
示例9: GenericTableMetaDataProvider
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
* Constructor used to initialize with provided database meta data.
* @param databaseMetaData meta data to be used
*/
protected GenericTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
this.userName = databaseMetaData.getUserName();
}
示例10: GenericCallMetaDataProvider
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
* Constructor used to initialize with provided database meta data.
* @param databaseMetaData meta data to be used
*/
protected GenericCallMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
this.userName = databaseMetaData.getUserName();
}