当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseMetaData.getUserName方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:22,代码来源:TestDatabaseMetaData.java

示例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();
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:24,代码来源:ExtendedPostgresDialect.java

示例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();
		}
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:27,代码来源:ExcelModelManager.java

示例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();
	}
}
 
开发者ID:yswang0927,项目名称:ralasafe,代码行数:10,代码来源:DBUtil.java

示例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);
	}
}
 
开发者ID:youseries,项目名称:ureport,代码行数:28,代码来源:DatasourceServletAction.java

示例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);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:33,代码来源:DbCommonServiceImpl.java

示例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;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:29,代码来源:QueryWizardPR.java

示例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;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:35,代码来源:DbJdbcUtils.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:GenericTableMetaDataProvider.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:GenericCallMetaDataProvider.java


注:本文中的java.sql.DatabaseMetaData.getUserName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。