List of usage examples for java.sql ResultSet getShort
short getShort(String columnLabel) throws SQLException;
ResultSet
object as a short
in the Java programming language. From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMySql.CFAstMySqlSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {//w ww . j a va 2 s. co m short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAstMySqlSchema.class, "getNullableInt64", e); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {//from w w w .ja va 2 s .c om short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAsteriskSybaseSchema.class, "getNullableInt64", e); } }
From source file:de.griffel.confluence.plugins.plantuml.AbstractDatabaseStructureMacroImpl.java
private void addIndexDetails(DatabaseMetaData dbmd, TableDef t) { final List<IndexDef> result = new LinkedList<IndexDef>(); if (_errorMessage == null && (_macroParams.isShowIndexes() || _macroParams.getTableTypes().contains("INDEX"))) { ResultSet rs = null; try {//www . j av a 2 s. c om rs = dbmd.getIndexInfo(t.getTableCatalog(), t.getTableSchema(), t.getTableName(), false, true); while (rs.next()) { IndexDef tmp = new IndexDef(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(5), rs.getString(6), rs.getShort(8), rs.getString(9)); result.add(tmp); if (log.isDebugEnabled()) { log.debug(tmp.getIndexId()); } } } catch (SQLException e) { sqlException(_macroParams.getDatasource(), e); } finally { closeResource(rs); } } t.setIndices(result); }
From source file:io.hops.metadata.ndb.dalimpl.hdfs.EncodingStatusClusterj.java
private List<EncodingStatus> find(String query) throws StorageException { ArrayList<EncodingStatus> resultList; try {/* ww w.j a v a 2s. c om*/ Connection conn = mysqlConnector.obtainSession(); PreparedStatement s = conn.prepareStatement(query); ResultSet result = s.executeQuery(); resultList = new ArrayList<EncodingStatus>(); while (result.next()) { Integer inodeId = result.getInt(INODE_ID); Integer parityInodeId = result.getInt(PARITY_INODE_ID); Integer status = result.getInt(STATUS); String codec = result.getString(CODEC); Short targetReplication = result.getShort(TARGET_REPLICATION); Long statusModificationTime = result.getLong(STATUS_MODIFICATION_TIME); Integer parityStatus = result.getInt(PARITY_STATUS); Long parityStatusModificationTime = result.getLong(PARITY_STATUS_MODIFICATION_TIME); String parityFileName = result.getString(PARITY_FILE_NAME); int lostBlocks = result.getInt(LOST_BLOCKS); int lostParityBlocks = result.getInt(LOST_PARITY_BLOCKS); Boolean revoked = NdbBoolean.convert(result.getByte(REVOKED)); EncodingPolicy policy = new EncodingPolicy(codec, targetReplication); resultList.add(new EncodingStatus(inodeId, parityInodeId, EncodingStatus.Status.values()[status], EncodingStatus.ParityStatus.values()[parityStatus], policy, statusModificationTime, parityStatusModificationTime, parityFileName, lostBlocks, lostParityBlocks, revoked)); } } catch (SQLException ex) { throw HopsSQLExceptionHelper.wrap(ex); } finally { mysqlConnector.closeSession(); } return resultList; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskOracle.CFAsteriskOracleSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {//from w ww . ja v a 2 s .c om short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAsteriskOracleSchema.class, "getNullableInt64", e); } }
From source file:net.sourceforge.msscodefactory.cfensyntax.v2_2.CFEnSyntaxMySql.CFEnSyntaxMySqlSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {//from w w w. j a v a 2 s.c o m short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFEnSyntaxMySqlSchema.class, "getNullableInt64", e); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstMSSql.CFAstMSSqlSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {/*from w w w .j a v a 2 s.c o m*/ short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAstMSSqlSchema.class, "getNullableInt64", e); } }
From source file:net.sourceforge.msscodefactory.cffreeswitch.v2_1.CFFswOracle.CFFswOracleSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {//from w w w . ja va 2 s. co m short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFFswOracleSchema.class, "getNullableInt64", e); } }
From source file:com.oltpbenchmark.catalog.Catalog.java
/** * Construct the set of Table objects from a given Connection handle * @param conn// w w w. j a v a 2 s. c om * @return * @throws SQLException * @see http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html */ protected void init() throws SQLException { // Load the database's DDL this.benchmark.createDatabase(DB_TYPE, this.conn); // TableName -> ColumnName -> <FkeyTable, FKeyColumn> Map<String, Map<String, Pair<String, String>>> foreignKeys = new HashMap<String, Map<String, Pair<String, String>>>(); DatabaseMetaData md = conn.getMetaData(); ResultSet table_rs = md.getTables(null, null, null, new String[] { "TABLE" }); while (table_rs.next()) { if (LOG.isDebugEnabled()) LOG.debug(SQLUtil.debug(table_rs)); String internal_table_name = table_rs.getString(3); String table_name = origTableNames.get(table_rs.getString(3).toUpperCase()); assert (table_name != null) : "Unexpected table '" + table_rs.getString(3) + "' from catalog"; LOG.debug(String.format("ORIG:%s -> CATALOG:%s", internal_table_name, table_name)); String table_type = table_rs.getString(4); if (table_type.equalsIgnoreCase("TABLE") == false) continue; Table catalog_tbl = new Table(table_name); // COLUMNS if (LOG.isDebugEnabled()) LOG.debug("Retrieving COLUMN information for " + table_name); ResultSet col_rs = md.getColumns(null, null, internal_table_name, null); while (col_rs.next()) { if (LOG.isTraceEnabled()) LOG.trace(SQLUtil.debug(col_rs)); String col_name = col_rs.getString(4); int col_type = col_rs.getInt(5); String col_typename = col_rs.getString(6); Integer col_size = col_rs.getInt(7); String col_defaultValue = col_rs.getString(13); boolean col_nullable = col_rs.getString(18).equalsIgnoreCase("YES"); boolean col_autoinc = false; // FIXME col_rs.getString(22).toUpperCase().equals("YES"); Column catalog_col = new Column(catalog_tbl, col_name, col_type, col_typename, col_size); catalog_col.setDefaultValue(col_defaultValue); catalog_col.setAutoincrement(col_autoinc); catalog_col.setNullable(col_nullable); // FIXME col_catalog.setSigned(); if (LOG.isDebugEnabled()) LOG.debug( String.format("Adding %s.%s [%s / %d]", table_name, col_name, col_typename, col_type)); catalog_tbl.addColumn(catalog_col); } // WHILE col_rs.close(); // PRIMARY KEYS if (LOG.isDebugEnabled()) LOG.debug("Retrieving PRIMARY KEY information for " + table_name); ResultSet pkey_rs = md.getPrimaryKeys(null, null, internal_table_name); SortedMap<Integer, String> pkey_cols = new TreeMap<Integer, String>(); while (pkey_rs.next()) { String col_name = pkey_rs.getString(4); assert (catalog_tbl.getColumnByName(col_name) != null) : String .format("Unexpected primary key column %s.%s", table_name, col_name); int col_idx = pkey_rs.getShort(5); // HACK: SQLite doesn't return the KEY_SEQ, so if we get back // a zero for this value, then we'll just length of the pkey_cols map if (col_idx == 0) col_idx = pkey_cols.size(); LOG.debug(String.format("PKEY[%02d]: %s.%s", col_idx, table_name, col_name)); assert (pkey_cols.containsKey(col_idx) == false); pkey_cols.put(col_idx, col_name); } // WHILE pkey_rs.close(); catalog_tbl.setPrimaryKeyColumns(pkey_cols.values()); // INDEXES if (LOG.isDebugEnabled()) LOG.debug("Retrieving INDEX information for " + table_name); ResultSet idx_rs = md.getIndexInfo(null, null, internal_table_name, false, false); while (idx_rs.next()) { if (LOG.isDebugEnabled()) LOG.debug(SQLUtil.debug(idx_rs)); boolean idx_unique = (idx_rs.getBoolean(4) == false); String idx_name = idx_rs.getString(6); int idx_type = idx_rs.getShort(7); int idx_col_pos = idx_rs.getInt(8) - 1; String idx_col_name = idx_rs.getString(9); String sort = idx_rs.getString(10); SortDirectionType idx_direction; if (sort != null) { idx_direction = sort.equalsIgnoreCase("A") ? SortDirectionType.ASC : SortDirectionType.DESC; } else idx_direction = null; Index catalog_idx = catalog_tbl.getIndex(idx_name); if (catalog_idx == null) { catalog_idx = new Index(catalog_tbl, idx_name, idx_type, idx_unique); catalog_tbl.addIndex(catalog_idx); } assert (catalog_idx != null); catalog_idx.addColumn(idx_col_name, idx_direction, idx_col_pos); } // WHILE idx_rs.close(); // FOREIGN KEYS if (LOG.isDebugEnabled()) LOG.debug("Retrieving FOREIGN KEY information for " + table_name); ResultSet fk_rs = md.getImportedKeys(null, null, internal_table_name); foreignKeys.put(table_name, new HashMap<String, Pair<String, String>>()); while (fk_rs.next()) { if (LOG.isDebugEnabled()) LOG.debug(table_name + " => " + SQLUtil.debug(fk_rs)); assert (fk_rs.getString(7).equalsIgnoreCase(table_name)); String colName = fk_rs.getString(8); String fk_tableName = origTableNames.get(fk_rs.getString(3).toUpperCase()); String fk_colName = fk_rs.getString(4); foreignKeys.get(table_name).put(colName, Pair.of(fk_tableName, fk_colName)); } // WHILE fk_rs.close(); tables.put(table_name, catalog_tbl); } // WHILE table_rs.close(); // FOREIGN KEYS if (LOG.isDebugEnabled()) LOG.debug("Foreign Key Mappings:\n" + StringUtil.formatMaps(foreignKeys)); for (Table catalog_tbl : tables.values()) { Map<String, Pair<String, String>> fk = foreignKeys.get(catalog_tbl.getName()); for (Entry<String, Pair<String, String>> e : fk.entrySet()) { String colName = e.getKey(); Column catalog_col = catalog_tbl.getColumnByName(colName); assert (catalog_col != null); Pair<String, String> fkey = e.getValue(); assert (fkey != null); Table fkey_tbl = tables.get(fkey.first); if (fkey_tbl == null) { throw new RuntimeException("Unexpected foreign key parent table " + fkey); } Column fkey_col = fkey_tbl.getColumnByName(fkey.second); if (fkey_col == null) { throw new RuntimeException("Unexpected foreign key parent column " + fkey); } if (LOG.isDebugEnabled()) LOG.debug(catalog_col.fullName() + " -> " + fkey_col.fullName()); catalog_col.setForeignKey(fkey_col); } // FOR } // FOR return; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskMySql.CFAsteriskMySqlSchema.java
public static Short getNullableInt16(ResultSet reader, int colidx) { try {/*from w w w . j ava2 s .c o m*/ short val = reader.getShort(colidx); if (reader.wasNull()) { return (null); } else { return (new Short(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAsteriskMySqlSchema.class, "getNullableInt64", e); } }