use of java.sql.DatabaseMetaData in project adempiere by adempiere.
the class TableCreateColumns method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
if (p_AD_Table_ID == 0)
throw new AdempiereSystemError("@NotFound@ @AD_Table_ID@ " + p_AD_Table_ID);
log.info("EntityType=" + p_EntityType + ", AllTables=" + p_AllTables + ", AD_Table_ID=" + p_AD_Table_ID);
//
Connection conn = null;
try {
conn = DB.getConnectionRO();
AdempiereDatabase db = DB.getDatabase();
DatabaseMetaData md = conn.getMetaData();
String catalog = db.getCatalog();
String schema = db.getSchema();
if (p_AllTables)
addTable(md, catalog, schema);
else {
MTable table = new MTable(getCtx(), p_AD_Table_ID, get_TrxName());
if (table == null || table.get_ID() == 0)
throw new AdempiereSystemError("@NotFound@ @AD_Table_ID@ " + p_AD_Table_ID);
log.info(table.getTableName() + ", EntityType=" + p_EntityType);
String tableName = table.getTableName();
if (DB.isOracle())
tableName = tableName.toUpperCase();
// globalqss 2005-10-24
if (DB.isPostgreSQL())
tableName = tableName.toLowerCase();
// end globalqss 2005-10-24
ResultSet rs = md.getColumns(catalog, schema, tableName, null);
addTableColumn(rs, table);
}
return "#" + m_count;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
}
}
}
}
use of java.sql.DatabaseMetaData in project adempiere by adempiere.
the class PackInHandler method createImp_Sum_table.
// startElement
/**
* Check if Package History Table exists in database. If not create
*
* @param tablename
*
*/
public void createImp_Sum_table(String tablename) {
// Check if table exists.
Connection conn = DB.getConnectionRW();
DatabaseMetaData dbm;
try {
dbm = conn.getMetaData();
// check if table is there
ResultSet tables = null;
if (m_DatabaseType.equals("Oracle"))
tables = dbm.getTables(null, null, tablename.toUpperCase(), null);
else if (m_DatabaseType.equals("PostgreSQL"))
tables = dbm.getTables(null, null, tablename.toLowerCase(), null);
if (tables.next()) {
log.info("Table Found");
} else {
if (tablename.equals("AD_Package_Imp")) {
StringBuffer sqlB = new StringBuffer("CREATE TABLE " + tablename.toUpperCase() + "( ").append(tablename.toUpperCase() + "_ID NUMBER(10) NOT NULL, ").append("AD_CLIENT_ID NUMBER(10) NOT NULL, ").append("AD_ORG_ID NUMBER(10) NOT NULL, ").append("ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, ").append("CREATED DATE DEFAULT SYSDATE NOT NULL, ").append("CREATEDBY NUMBER(10) NOT NULL, ").append("UPDATED DATE DEFAULT SYSDATE NOT NULL, ").append("UPDATEDBY NUMBER(10) NOT NULL, ").append("NAME NVARCHAR2(60) NOT NULL, ").append("PK_STATUS NVARCHAR2(22), ").append("RELEASENO NVARCHAR2(20), ").append("PK_VERSION NVARCHAR2(20), ").append("VERSION NVARCHAR2(20), ").append("DESCRIPTION NVARCHAR2(1000) NOT NULL, ").append("EMAIL NVARCHAR2(60), ").append("PROCESSED CHAR(1) DEFAULT 'N', ").append("PROCESSING CHAR(1) DEFAULT 'N', ").append("CREATOR VARCHAR2(60 ), ").append("CREATORCONTACT VARCHAR2(255), ").append(" CREATEDDATE VARCHAR2(25), ").append("UPDATEDDATE VARCHAR2(25), ").append("PRIMARY KEY( " + tablename.toUpperCase() + "_ID)" + ")");
try {
PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
pstmt.executeUpdate();
MSequence.createTableSequence(m_ctx, "AD_Package_Imp", m_trxName);
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.info("createImp_Sum_table:" + e);
}
}
if (tablename.equals("AD_Package_Imp_Inst")) {
StringBuffer sqlB = new StringBuffer("CREATE TABLE " + tablename.toUpperCase() + "( ").append(tablename.toUpperCase() + "_ID NUMBER(10) NOT NULL, ").append("AD_CLIENT_ID NUMBER(10) NOT NULL, ").append("AD_ORG_ID NUMBER(10) NOT NULL, ").append("ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, ").append("CREATED DATE DEFAULT SYSDATE NOT NULL, ").append("CREATEDBY NUMBER(10) NOT NULL, ").append("UPDATED DATE DEFAULT SYSDATE NOT NULL, ").append("UPDATEDBY NUMBER(10) NOT NULL, ").append("NAME NVARCHAR2(60) NOT NULL, ").append("PK_STATUS NVARCHAR2(22), ").append("RELEASENO NVARCHAR2(20), ").append("PK_VERSION NVARCHAR2(20), ").append("VERSION NVARCHAR2(20), ").append("DESCRIPTION NVARCHAR2(1000) NOT NULL, ").append("EMAIL NVARCHAR2(60), ").append("PROCESSED CHAR(1) DEFAULT 'N', ").append("PROCESSING CHAR(1) DEFAULT 'N', ").append("CREATOR VARCHAR2(60 ), ").append("CREATORCONTACT VARCHAR2(255), ").append(" CREATEDDATE VARCHAR2(25), ").append("UPDATEDDATE VARCHAR2(25), ").append("PRIMARY KEY( " + tablename.toUpperCase() + "_ID)" + ")");
try {
PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
pstmt.executeUpdate();
MSequence.createTableSequence(m_ctx, "AD_Package_Imp_Inst", m_trxName);
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.info("createImp_Sum_table:" + e);
}
}
if (tablename.equals("AD_Package_Imp_Detail")) {
StringBuffer sqlB = new StringBuffer("CREATE TABLE " + tablename.toUpperCase() + "( ").append(tablename.toUpperCase() + "_ID NUMBER(10) NOT NULL, ").append("AD_CLIENT_ID NUMBER(10) NOT NULL, ").append("AD_ORG_ID NUMBER(10) NOT NULL, ").append("ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, ").append("CREATED DATE DEFAULT SYSDATE NOT NULL, ").append("CREATEDBY NUMBER(10) NOT NULL, ").append("UPDATED DATE DEFAULT SYSDATE NOT NULL, ").append("UPDATEDBY NUMBER(10) NOT NULL, ").append("NAME NVARCHAR2(60), ").append("AD_PACKAGE_IMP_ID Number(10) NOT NULL, ").append("AD_ORIGINAL_ID Number(10) NOT NULL, ").append("AD_BACKUP_ID Number(10), ").append("ACTION NVARCHAR2(20), ").append("SUCCESS NVARCHAR2(20), ").append("TYPE NVARCHAR2(60), ").append("TABLENAME NVARCHAR2(60), ").append("AD_TABLE_ID NUMBER(10), ").append("UNINSTALL CHAR(1), ").append("PRIMARY KEY( " + tablename.toUpperCase() + "_ID)" + ")");
try {
PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
pstmt.executeUpdate();
MSequence.createTableSequence(m_ctx, "AD_Package_Imp_Detail", m_trxName);
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.info("createImp_Sum_table:" + e);
}
}
if (tablename.equals("AD_Package_Imp_Backup")) {
StringBuffer sqlB = new StringBuffer("CREATE TABLE " + tablename.toUpperCase() + "( ").append(tablename.toUpperCase() + "_ID NUMBER(10) NOT NULL, ").append("AD_CLIENT_ID NUMBER(10) NOT NULL, ").append("AD_ORG_ID NUMBER(10) NOT NULL, ").append("ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, ").append("CREATED DATE DEFAULT SYSDATE NOT NULL, ").append("CREATEDBY NUMBER(10) NOT NULL, ").append("UPDATED DATE DEFAULT SYSDATE NOT NULL, ").append("UPDATEDBY NUMBER(10) NOT NULL, ").append("AD_PACKAGE_IMP_ID Number(10) NOT NULL, ").append("AD_PACKAGE_IMP_DETAIL_ID Number(10) NOT NULL, ").append("AD_TABLE_ID NUMBER(10), ").append("AD_COLUMN_ID NUMBER(10), ").append("AD_REFERENCE_ID NUMBER(10), ").append("AD_PACKAGE_IMP_BCK_DIR NVARCHAR2(255), ").append("AD_PACKAGE_IMP_ORG_DIR NVARCHAR2(255), ").append("COLVALUE NVARCHAR2(2000), ").append("UNINSTALL CHAR(1), ").append("PRIMARY KEY( " + tablename.toUpperCase() + "_ID)" + ")");
try {
PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
pstmt.executeUpdate();
MSequence.createTableSequence(m_ctx, "AD_Package_Imp_Backup", m_trxName);
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.info("createImp_Sum_table:" + e);
}
}
}
tables.close();
} catch (SQLException e) {
log.info("createImp_Sum_table:" + e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
}
}
}
}
use of java.sql.DatabaseMetaData in project aries by apache.
the class Connector method initialize.
public void initialize() throws SQLException {
conn = connect();
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getTables(null, "", "TESTTABLE", null);
if (!rs.next()) {
executeUpdate("CREATE TABLE TESTTABLE (NAME VARCHAR(64), VALUE INTEGER, PRIMARY KEY(NAME, VALUE))");
}
}
use of java.sql.DatabaseMetaData in project aries by apache.
the class TradeDBManagerImpl method checkDBProductName.
/**
* Return a String containing the DBProductName configured for
* the current DataSource
*
* used by TradeBuildDB
*
* @return A String of the currently configured DataSource
*
*/
public String checkDBProductName() throws Exception {
Connection conn = null;
String dbProductName = null;
try {
if (Log.doTrace())
Log.traceEnter("TradeDBManagerImpl:checkDBProductName");
conn = getConn();
DatabaseMetaData dbmd = conn.getMetaData();
dbProductName = dbmd.getDatabaseProductName();
} catch (SQLException e) {
Log.error(e, "TradeDBManagerImpl:checkDBProductName() -- Error checking the AriesTrader Database Product Name");
} finally {
releaseConn(conn);
}
return dbProductName;
}
use of java.sql.DatabaseMetaData in project calcite-avatica by apache.
the class MetaResultSetTest method testGetColumnPrivileges.
@Test
public void testGetColumnPrivileges() throws SQLException {
DatabaseMetaData metadata = getDatabaseMetadata();
try (ResultSet rs = metadata.getColumnPrivileges(null, null, null, null)) {
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals(8, rsMeta.getColumnCount());
assertColumn(rsMeta, 1, "TABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 2, "TABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 3, "TABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 4, "COLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 5, "GRANTOR", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 6, "GRANTEE", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 7, "PRIVILEGE", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 8, "IS_GRANTABLE", Types.VARCHAR, DatabaseMetaData.columnNullable);
}
}
Aggregations