本文整理汇总了Java中java.sql.DatabaseMetaData.getSchemas方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMetaData.getSchemas方法的具体用法?Java DatabaseMetaData.getSchemas怎么用?Java DatabaseMetaData.getSchemas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.DatabaseMetaData
的用法示例。
在下文中一共展示了DatabaseMetaData.getSchemas方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieveSchemas
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Override
protected boolean retrieveSchemas(SchemaPanel schemaPanel, DatabaseConnection dbcon, String defaultSchema) {
fireConnectionStep(NbBundle.getMessage (ConnectAction.class, "ConnectionProgress_Schemas")); // NOI18N
List<String> schemas = new ArrayList<String> ();
try {
DatabaseMetaData dbMetaData = dbcon.getJDBCConnection().getMetaData();
if (dbMetaData.supportsSchemasInTableDefinitions()) {
ResultSet rs = dbMetaData.getSchemas();
if (rs != null) {
while (rs.next()) {
schemas.add(rs.getString(1).trim());
}
}
}
} catch (SQLException exc) {
String message = NbBundle.getMessage(ConnectAction.class, "ERR_UnableObtainSchemas", exc.getMessage()); // NOI18N
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE));
}
return schemaPanel.setSchemas(schemas, defaultSchema);
}
示例2: retrieveSchemas
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Override
protected boolean retrieveSchemas(SchemaPanel schemaPanel, DatabaseConnection dbcon, String defaultSchema) {
fireConnectionStep(NbBundle.getMessage (ConnectUsingDriverAction.class, "ConnectionProgress_Schemas")); // NOI18N
List<String> schemas = new ArrayList<String>();
try {
DatabaseMetaData dbMetaData = dbcon.getJDBCConnection().getMetaData();
if (dbMetaData.supportsSchemasInTableDefinitions()) {
ResultSet rs = dbMetaData.getSchemas();
if (rs != null) {
while (rs.next()) {
schemas.add(rs.getString(1).trim());
}
}
}
} catch (SQLException exc) {
String message = NbBundle.getMessage(ConnectUsingDriverAction.class, "ERR_UnableObtainSchemas", exc.getMessage()); // NOI18N
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE));
}
return schemaPanel.setSchemas(schemas, defaultSchema);
}
示例3: listSchemasTest
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Test
public void listSchemasTest() throws SQLException {
DatabaseMetaData meta = connection.getMetaData();
String catalog = null;
String schemaPattern = null;
System.out.println("Querying for all Schemas...");
ResultSet schema = meta.getSchemas(catalog, schemaPattern);
int schemaCount = 0;
while (schema.next()) {
String catalogName = schema.getString("TABLE_CATALOG");
String schemaName = schema.getString("TABLE_SCHEM");
System.out.println(catalogName + ":" + schemaName);
schemaCount++;
}
assertTrue(schemaCount > 0);
}
示例4: 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();
}
}
示例5: getSeriesList
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Override
public List<String> getSeriesList()
{
List<String> ret = new ArrayList<String>();
try
{
DatabaseMetaData meta = getConnection().getMetaData();
ResultSet rs = meta.getSchemas();
while (rs.next()) {
String s = rs.getString("TABLE_SCHEM");
if (!ignore.contains(s))
ret.add(s);
}
rs.close();
}
catch (SQLException sqle)
{
logError("getSeriesList", sqle);
}
return ret;
}
示例6: schemaExists
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public boolean schemaExists(Connection conn, String schemaName) throws Exception {
DatabaseMetaData md = conn.getMetaData();
ResultSet rs = md.getSchemas();
while ( rs.next() ) {
if ( schemaName.toLowerCase().equals(rs.getString(1).toLowerCase())) {
return true;
}
}
return false;
}
示例7: testTwo
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
* Basic test of DatabaseMetaData functions that access system tables
*/
public void testTwo() throws Exception {
Connection conn = newConnection();
int updateCount;
try {
TestUtil.testScript(conn, "testrun/hsqldb/TestSelf.txt");
DatabaseMetaData dbmeta = conn.getMetaData();
dbmeta.allProceduresAreCallable();
dbmeta.getBestRowIdentifier(null, null, "T_1",
DatabaseMetaData.bestRowTransaction,
true);
dbmeta.getCatalogs();
dbmeta.getColumnPrivileges(null, "PUBLIC", "T_1", "%");
dbmeta.getColumns("PUBLIC", "PUBLIC", "T_1", "%");
dbmeta.getCrossReference(null, null, "T_1", null, null, "T_1");
dbmeta.getExportedKeys(null, null, "T_1");
dbmeta.getFunctionColumns(null, "%", "%", "%");
dbmeta.getFunctions(null, "%", "%");
dbmeta.getImportedKeys("PUBLIC", "PUBLIC", "T_1");
dbmeta.getIndexInfo("PUBLIC", "PUBLIC", "T1", true, true);
dbmeta.getPrimaryKeys("PUBLIC", "PUBLIC", "T_1");
dbmeta.getProcedureColumns(null, null, "%", "%");
dbmeta.getProcedures("PUBLIC", "%", "%");
dbmeta.getSchemas(null, "#");
dbmeta.getTablePrivileges(null, "%", "%");
dbmeta.getUDTs(null, "%", "%", new int[]{ Types.DISTINCT });
} catch (Exception e) {
assertTrue("unable to prepare or execute DDL", false);
} finally {
conn.close();
}
}
示例8: getAllSchemasFromDB
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
public static String[] getAllSchemasFromDB(String dsName) {
Connection conn = null;
ResultSet rs = null;
try {
conn = DBPower.getConnection(dsName);
DatabaseMetaData metaData = conn.getMetaData();
String databaseProductName = DBUtil.getDatabaseProductName(conn);
if (databaseProductName == DBUtil.MYSQL
|| databaseProductName == DBUtil.SQLSERVER) {
rs = metaData.getCatalogs();
} else {
rs = metaData.getSchemas();
}
List result = new LinkedList();
while (rs.next()) {
String name = rs.getString(1);
result.add(name);
}
String[] names = new String[result.size()];
Iterator itr = result.iterator();
for (int i = 0; i < names.length; i++) {
names[i] = (String) itr.next();
}
return names;
} catch (SQLException e) {
log.error( "", e );
throw new DBLevelException(e);
} finally {
DBUtil.close(rs);
DBUtil.close(conn);
}
}
示例9: testGetSchemas
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
@Test public void testGetSchemas() throws SQLException {
DatabaseMetaData metadata = getDatabaseMetadata();
try (ResultSet rs = metadata.getSchemas(null, null)) {
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals(2, rsMeta.getColumnCount());
assertColumn(rsMeta, 1, "TABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 2, "TABLE_CATALOG", Types.VARCHAR, DatabaseMetaData.columnNullable);
}
}
示例10: runOtherMetaDataTests
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
private void runOtherMetaDataTests() throws SQLException
{
DatabaseMetaData metadata = connection.getMetaData();
try (ResultSet rs = metadata.getCatalogs())
{
}
try (ResultSet rs = metadata.getAttributes("", "", null, null))
{
}
try (ResultSet rs = metadata.getClientInfoProperties())
{
}
try (ResultSet rs = metadata.getFunctionColumns("", "", null, null))
{
}
try (ResultSet rs = metadata.getFunctions("", "", null))
{
}
try (ResultSet rs = metadata.getProcedureColumns("", "", null, null))
{
}
try (ResultSet rs = metadata.getProcedures("", "", null))
{
}
try (ResultSet rs = metadata.getSchemas())
{
}
try (ResultSet rs = metadata.getSchemas("", null))
{
}
try (ResultSet rs = metadata.getSuperTypes("", "", null))
{
}
try (ResultSet rs = metadata.getTableTypes())
{
}
try (ResultSet rs = metadata.getTypeInfo())
{
}
try (ResultSet rs = metadata.getUDTs(null, null, null, null))
{
}
for (String table : TABLES)
{
try (ResultSet rs = metadata.getExportedKeys("", "", table))
{
}
try (ResultSet rs = metadata.getImportedKeys("", "", table))
{
}
try (ResultSet rs = metadata.getBestRowIdentifier("", "", table, DatabaseMetaData.bestRowTransaction,
false))
{
}
try (ResultSet rs = metadata.getColumnPrivileges("", "", table, null))
{
}
try (ResultSet rs = metadata.getPrimaryKeys("", "", table))
{
}
try (ResultSet rs = metadata.getPseudoColumns("", "", table, null))
{
}
try (ResultSet rs = metadata.getSuperTables("", "", table))
{
}
try (ResultSet rs = metadata.getTablePrivileges("", "", table))
{
}
try (ResultSet rs = metadata.getVersionColumns("", "", table))
{
}
}
}
示例11: testBug23304
import java.sql.DatabaseMetaData; //导入方法依赖的package包/类
/**
* Tests fix for BUG#23304 - DBMD using "show" and DBMD using
* information_schema do not return results consistent with eachother.
*
* (note this fix only addresses the inconsistencies, not the issue that the
* driver is treating schemas differently than some users expect.
*
* We will revisit this behavior when there is full support for schemas in
* MySQL).
*
* @throws Exception
*/
public void testBug23304() throws Exception {
if (!versionMeetsMinimum(5, 0)) {
return;
}
Connection connShow = null;
Connection connInfoSchema = null;
ResultSet rsShow = null;
ResultSet rsInfoSchema = null;
try {
Properties noInfoSchemaProps = new Properties();
noInfoSchemaProps.setProperty("useInformationSchema", "false");
Properties infoSchemaProps = new Properties();
infoSchemaProps.setProperty("useInformationSchema", "true");
infoSchemaProps.setProperty("dumpQueriesOnException", "true");
connShow = getConnectionWithProps(noInfoSchemaProps);
connInfoSchema = getConnectionWithProps(infoSchemaProps);
DatabaseMetaData dbmdUsingShow = connShow.getMetaData();
DatabaseMetaData dbmdUsingInfoSchema = connInfoSchema.getMetaData();
assertNotSame(dbmdUsingShow.getClass(), dbmdUsingInfoSchema.getClass());
rsShow = dbmdUsingShow.getSchemas();
rsInfoSchema = dbmdUsingInfoSchema.getSchemas();
compareResultSets(rsShow, rsInfoSchema);
/*
* rsShow = dbmdUsingShow.getTables(connShow.getCatalog(), null,
* "%", new String[] {"TABLE", "VIEW"}); rsInfoSchema =
* dbmdUsingInfoSchema.getTables(connInfoSchema.getCatalog(), null,
* "%", new String[] {"TABLE", "VIEW"});
*
* compareResultSets(rsShow, rsInfoSchema);
*
* rsShow = dbmdUsingShow.getTables(null, null, "%", new String[]
* {"TABLE", "VIEW"}); rsInfoSchema =
* dbmdUsingInfoSchema.getTables(null, null, "%", new String[]
* {"TABLE", "VIEW"});
*
* compareResultSets(rsShow, rsInfoSchema);
*/
createTable("t_testBug23304",
"(field1 int primary key not null, field2 tinyint, field3 mediumint, field4 mediumint, field5 bigint, field6 float, field7 double, field8 decimal, field9 char(32), field10 varchar(32), field11 blob, field12 mediumblob, field13 longblob, field14 text, field15 mediumtext, field16 longtext, field17 date, field18 time, field19 datetime, field20 timestamp)");
rsShow = dbmdUsingShow.getColumns(connShow.getCatalog(), null, "t_testBug23304", "%");
rsInfoSchema = dbmdUsingInfoSchema.getColumns(connInfoSchema.getCatalog(), null, "t_testBug23304", "%");
compareResultSets(rsShow, rsInfoSchema);
} finally {
if (rsShow != null) {
rsShow.close();
}
if (rsInfoSchema != null) {
rsInfoSchema.close();
}
}
}