use of java.sql.DatabaseMetaData in project GameCore by Warvale.
the class SQLUtil method tableExists.
public static boolean tableExists(SQLConnection connection, String table) throws ClassNotFoundException, SQLException {
checkAndOpen(connection);
Connection c = connection.getConnection();
DatabaseMetaData metaData = c.getMetaData();
ResultSet rs = metaData.getTables(null, null, table, null);
if (rs.next()) {
return rs.getRow() == 1;
}
return false;
}
use of java.sql.DatabaseMetaData in project ats-framework by Axway.
the class MysqlEnvironmentHandler method checkDriverVersion.
private boolean checkDriverVersion(MysqlDbProvider dbProvider) {
try {
Connection connection = dbProvider.getConnection();
DatabaseMetaData dmd = connection.getMetaData();
int majorVersion = dmd.getDriverMajorVersion();
int minorVersion = dmd.getDriverMinorVersion();
log.info(new StringBuilder().append("JDBC driver used is : ").append(majorVersion).append(".").append(minorVersion).toString());
// The older specification is used in drivers prior to 5.0 including 5.0
if (majorVersion < 5) {
return false;
} else if (majorVersion == 5 && minorVersion == 0) {
return false;
}
} catch (SQLException e) {
log.error("Unable to determine driver version, falling back to JDBC3 specs", e);
return false;
} catch (DbException e) {
log.error("Unable to determine driver version, falling back to JDBC3 specs", e);
return false;
}
return true;
}
use of java.sql.DatabaseMetaData in project ats-framework by Axway.
the class AbstractDbProvider method getTableDescriptions.
/**
* @return description about all tables present in the database
*/
@Override
public List<TableDescription> getTableDescriptions() {
ResultSet tablesResultSet = null;
List<TableDescription> tables = new ArrayList<TableDescription>();
try (Connection connection = ConnectionPool.getConnection(dbConnection)) {
DatabaseMetaData databaseMetaData = connection.getMetaData();
tablesResultSet = databaseMetaData.getTables(null, null, null, new String[] { "TABLE" });
while (tablesResultSet.next()) {
if (this instanceof OracleDbProvider && !tablesResultSet.getString(2).equalsIgnoreCase(dbConnection.user)) {
// Oracle gives us all tables from all databases, we filter here only ours
continue;
}
String tableName = tablesResultSet.getString("TABLE_NAME");
if (!isTableAccepted(tablesResultSet, dbConnection.db, tableName)) {
// Table is skipped
continue;
}
log.debug("Extracting description about '" + tableName + "' table");
TableDescription table = new TableDescription();
table.setName(tableName);
table.setSchema(tablesResultSet.getString("TABLE_SCHEM"));
table.setPrimaryKeyColumn(exctractPrimaryKeyColumn(tableName, databaseMetaData));
table.setIndexes(extractTableIndexes(tableName, databaseMetaData, connection.getCatalog()));
List<String> columnDescriptions = new ArrayList<>();
extractTableColumns(tableName, databaseMetaData, columnDescriptions);
table.setColumnDescriptions(columnDescriptions);
tables.add(table);
}
} catch (SQLException sqle) {
throw new DbException("Error extracting DB schema information", sqle);
} finally {
if (tablesResultSet != null) {
try {
tablesResultSet.close();
} catch (SQLException e) {
log.warn("Result set resouce could not be closed!", e);
}
}
}
return tables;
}
use of java.sql.DatabaseMetaData in project opennms by OpenNMS.
the class JDBCDetectorIT method setUp.
@Before
public void setUp() throws UnknownHostException, SQLException {
MockLogAppender.setupLogging();
m_detector = m_detectorFactory.createDetector();
String url = null;
String username = null;
Connection conn = null;
try {
conn = m_dataSource.getConnection();
DatabaseMetaData metaData = conn.getMetaData();
url = metaData.getURL();
username = metaData.getUserName();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
if (conn != null) {
conn.close();
}
}
m_detector.setDbDriver("org.postgresql.Driver");
m_detector.setPort(5432);
m_detector.setUrl(url);
m_detector.setUser(username);
m_detector.setPassword("");
}
use of java.sql.DatabaseMetaData in project opennms by OpenNMS.
the class JdbcQueryDetectorIT method setUp.
@Before
public void setUp() throws SQLException {
MockLogAppender.setupLogging();
m_detector = m_detectorFactory.createDetector();
String url = null;
String username = null;
Connection conn = null;
try {
conn = m_dataSource.getConnection();
DatabaseMetaData metaData = conn.getMetaData();
url = metaData.getURL();
username = metaData.getUserName();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
if (conn != null) {
conn.close();
}
}
m_detector.setDbDriver("org.postgresql.Driver");
m_detector.setPort(5432);
m_detector.setUrl(url);
m_detector.setUser(username);
m_detector.setPassword("");
m_detector.setSqlQuery("select count(nodeid) from node");
}
Aggregations