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:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); ResultSet indexInformation = null; DatabaseMetaData meta = conn.getMetaData(); // The '_' character represents any single character. // The '%' character represents any sequence of zero // or more characters. indexInformation = meta.getIndexInfo(conn.getCatalog(), null, "survey", true, true); while (indexInformation.next()) { short type = indexInformation.getShort("TYPE"); switch (type) { case DatabaseMetaData.tableIndexClustered: System.out.println("tableIndexClustered"); case DatabaseMetaData.tableIndexHashed: System.out.println("tableIndexHashed"); case DatabaseMetaData.tableIndexOther: System.out.println("tableIndexOther"); case DatabaseMetaData.tableIndexStatistic: System.out.println("tableIndexStatistic"); default://from ww w .j ava 2s . c o m System.out.println("tableIndexOther"); } } st.close(); conn.close(); }
From source file:ForeignKeysCoffees.java
public static void main(String args[]) { String url = "jdbc:mySubprotocol:myDataSource"; Connection con;// w ww. j ava 2 s .c om String createString = "create table COFFEESFK " + "(COF_NAME varchar(32) NOT NULL, " + "SUP_ID int, " + "PRICE float, " + "SALES int, " + "TOTAL int, " + "primary key(COF_NAME), " + "foreign key(SUP_ID) references SUPPLIERSPK)"; Statement stmt; try { Class.forName("myDriver.ClassName"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { con = DriverManager.getConnection(url, "myLogin", "myPassword"); stmt = con.createStatement(); stmt.executeUpdate(createString); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getImportedKeys(null, null, "COFFEESFK"); while (rs.next()) { String pkTable = rs.getString("PKTABLE_NAME"); String pkColName = rs.getString("PKCOLUMN_NAME"); String fkTable = rs.getString("FKTABLE_NAME"); String fkColName = rs.getString("FKCOLUMN_NAME"); short updateRule = rs.getShort("UPDATE_RULE"); short deleteRule = rs.getShort("DELETE_RULE"); System.out.println("primary key table name : " + pkTable); System.out.print("primary key column name : "); System.out.println(pkColName); System.out.println("foreign key table name : " + fkTable); System.out.print("foreign key column name : "); System.out.println(fkColName); System.out.println("update rule: " + updateRule); System.out.println("delete rule: " + deleteRule); System.out.println(""); } rs.close(); stmt.close(); con.close(); } catch (SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); DatabaseMetaData dbMetaData = conn.getMetaData(); ResultSet rs = dbMetaData.getProcedureColumns(conn.getCatalog(), null, "procedureNamePattern", "columnNamePattern"); while (rs.next()) { // get stored procedure metadata String procedureCatalog = rs.getString(1); String procedureSchema = rs.getString(2); String procedureName = rs.getString(3); String columnName = rs.getString(4); short columnReturn = rs.getShort(5); int columnDataType = rs.getInt(6); String columnReturnTypeName = rs.getString(7); int columnPrecision = rs.getInt(8); int columnByteLength = rs.getInt(9); short columnScale = rs.getShort(10); short columnRadix = rs.getShort(11); short columnNullable = rs.getShort(12); String columnRemarks = rs.getString(13); System.out.println("stored Procedure name=" + procedureName); System.out.println("procedureCatalog=" + procedureCatalog); System.out.println("procedureSchema=" + procedureSchema); System.out.println("procedureName=" + procedureName); System.out.println("columnName=" + columnName); System.out.println("columnReturn=" + columnReturn); System.out.println("columnDataType=" + columnDataType); System.out.println("columnReturnTypeName=" + columnReturnTypeName); System.out.println("columnPrecision=" + columnPrecision); System.out.println("columnByteLength=" + columnByteLength); System.out.println("columnScale=" + columnScale); System.out.println("columnRadix=" + columnRadix); System.out.println("columnNullable=" + columnNullable); System.out.println("columnRemarks=" + columnRemarks); }/* ww w . ja v a2 s . c o m*/ st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); ResultSet indexInformation = null; DatabaseMetaData meta = conn.getMetaData(); // The '_' character represents any single character. // The '%' character represents any sequence of zero // or more characters. indexInformation = meta.getIndexInfo(conn.getCatalog(), null, "survey", true, true); while (indexInformation.next()) { String dbCatalog = indexInformation.getString("TABLE_CATALOG"); String dbSchema = indexInformation.getString("TABLE_SCHEMA"); String dbTableName = indexInformation.getString("TABLE_NAME"); boolean dbNoneUnique = indexInformation.getBoolean("NON_UNIQUE"); String dbIndexQualifier = indexInformation.getString("INDEX_QUALIFIER"); String dbIndexName = indexInformation.getString("INDEX_NAME"); short dbType = indexInformation.getShort("TYPE"); short dbOrdinalPosition = indexInformation.getShort("ORDINAL_POSITION"); String dbColumnName = indexInformation.getString("COLUMN_NAME"); String dbAscOrDesc = indexInformation.getString("ASC_OR_DESC"); int dbCardinality = indexInformation.getInt("CARDINALITY"); int dbPages = indexInformation.getInt("PAGES"); String dbFilterCondition = indexInformation.getString("FILTER_CONDITION"); System.out.println("index name=" + dbIndexName); System.out.println("table=" + dbTableName); System.out.println("column=" + dbColumnName); System.out.println("catalog=" + dbCatalog); System.out.println("schema=" + dbSchema); System.out.println("nonUnique=" + dbNoneUnique); System.out.println("indexQualifier=" + dbIndexQualifier); System.out.println("type=" + dbType); System.out.println("ordinalPosition=" + dbOrdinalPosition); System.out.println("ascendingOrDescending=" + dbAscOrDesc); System.out.println("cardinality=" + dbCardinality); System.out.println("pages=" + dbPages); System.out.println("filterCondition=" + dbFilterCondition); }//from www. j a v a 2 s . c om st.close(); conn.close(); }
From source file:de.erdesignerng.dialect.msaccess.MSAccessFileFormat.java
private static int getTableCount(Connection aConnection, String aTableName) throws SQLException { String theColumnName = "theCount"; short theResult = 0; String theSQL = "SELECT Count(MSysObjects.Id) AS " + theColumnName + " " + "FROM MSysObjects " + "WHERE (MSysObjects.Name LIKE ?);"; PreparedStatement theStatement = aConnection.prepareStatement(theSQL); theStatement.setString(1, aTableName); ResultSet theIdentificationResult = theStatement.executeQuery(); if (theIdentificationResult != null) { if (theIdentificationResult.next()) { theResult = theIdentificationResult.getShort(theColumnName); }//from ww w.j a v a 2 s . c o m theIdentificationResult.close(); } return theResult; }
From source file:jp.co.golorp.emarf.sql.MetaData.java
/** * @param rs/*from w w w. ja va2s .c om*/ * rs * @param columnInfoName * columnLabel * @return String */ private static Short getShort(final ResultSet rs, final String columnInfoName) { try { LOG.trace(columnInfoName + ":" + rs.getString(columnInfoName)); return rs.getShort(columnInfoName); } catch (SQLException e) { NOT_EXIST_COLUMN_INFO_NAMES.add(columnInfoName); } return null; }
From source file:com.wabacus.system.datatype.ShortType.java
public Object getColumnValue(ResultSet rs, int iindex, AbsDatabaseType dbtype) throws SQLException { return Short.valueOf(rs.getShort(iindex)); }
From source file:com.wabacus.system.datatype.ShortType.java
public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException { return Short.valueOf(rs.getShort(column)); }
From source file:com.sqewd.open.dal.core.persistence.db.EntityHelper.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void setColumnValue(final ResultSet rs, final StructAttributeReflect attr, final AbstractEntity entity, final AbstractJoinGraph gr, final Stack<KeyValuePair<Class<?>>> path) throws Exception { KeyValuePair<String> alias = gr.getAliasFor(path, attr.Column, 0); String tabprefix = alias.getKey(); if (EnumPrimitives.isPrimitiveType(attr.Field.getType())) { EnumPrimitives prim = EnumPrimitives.type(attr.Field.getType()); switch (prim) { case ECharacter: String sv = rs.getString(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), sv.charAt(0)); }//w w w . j av a 2 s . c om break; case EShort: short shv = rs.getShort(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), shv); } break; case EInteger: int iv = rs.getInt(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), iv); } break; case ELong: long lv = rs.getLong(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), lv); } break; case EFloat: float fv = rs.getFloat(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), fv); } break; case EDouble: double dv = rs.getDouble(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), dv); } break; default: throw new Exception("Unsupported Data type [" + prim.name() + "]"); } } else if (attr.Convertor != null) { String value = rs.getString(tabprefix + "." + attr.Column); if (!rs.wasNull()) { attr.Convertor.load(entity, attr.Column, value); } } else if (attr.Field.getType().equals(String.class)) { String value = rs.getString(tabprefix + "." + attr.Column); if (!rs.wasNull()) { PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), value); } } else if (attr.Field.getType().equals(Date.class)) { long value = rs.getLong(tabprefix + "." + attr.Column); if (!rs.wasNull()) { Date dt = new Date(value); PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), dt); } } else if (attr.Field.getType().isEnum()) { String value = rs.getString(tabprefix + "." + attr.Column); if (!rs.wasNull()) { Class ecls = attr.Field.getType(); Object evalue = Enum.valueOf(ecls, value); PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), evalue); } } else if (attr.Reference != null) { Class<?> rt = Class.forName(attr.Reference.Class); Object obj = rt.newInstance(); if (!(obj instanceof AbstractEntity)) throw new Exception("Unsupported Entity type [" + rt.getCanonicalName() + "]"); AbstractEntity rentity = (AbstractEntity) obj; if (path.size() > 0) { path.peek().setKey(attr.Column); } KeyValuePair<Class<?>> cls = new KeyValuePair<Class<?>>(); cls.setValue(rentity.getClass()); path.push(cls); setEntity(rentity, rs, gr, path); PropertyUtils.setSimpleProperty(entity, attr.Field.getName(), rentity); path.pop(); } }
From source file:net.freechoice.model.orm.Map_Post.java
@Override public FC_Post mapRow(final ResultSet rs, int rowNum) throws SQLException { FC_Post post = new FC_Post(); post.id = rs.getInt(1);//from ww w .j a v a 2 s . c o m post.status = rs.getShort(2); post.id_author = rs.getInt(3); post.name_author = rs.getString(4); post.time_posted = rs.getTimestamp(5); post.num_read = rs.getInt(6); post.num_comment = rs.getInt(7); post.title = rs.getString(8); post.content = rs.getString(9); return post; }