本文整理汇总了Java中java.sql.Types.STRUCT属性的典型用法代码示例。如果您正苦于以下问题:Java Types.STRUCT属性的具体用法?Java Types.STRUCT怎么用?Java Types.STRUCT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.sql.Types
的用法示例。
在下文中一共展示了Types.STRUCT属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
@Override
public void run() {
SQLServerPreparedStatement stmt = (SQLServerPreparedStatement) statement;
try {
switch (type) {
// TODO: Add all types
case Types.STRUCT:
if (objects.length == 2) {
stmt.setStructured(index, (String) objects[0], (SQLServerDataTable) objects[1]);
}
break;
default:
throw new RuntimeException("Not Supported yet!",
new UnsupportedOperationException(String.format("This SQL Type (%1$s) cannot be added to the statement using this"
+ " method. Please add the same as an inline parameter at %2$s index.", type, index)));
}
}
catch (SQLServerException ex) {
throw new RuntimeException(ex);
}
}
示例2: treatReturn
/**
* Tratar o retorno vido do java
* @param result
* @param returnType
* @return
*/
@SuppressWarnings("CallToPrintStackTrace")
private static Object treatReturn (Object result, int returnType)
{
Object currectObject = result;
try
{
if (returnType == ARRAY && result instanceof Array)
{
Array r = (Array) result;
currectObject = new ArrayList<> (Arrays.asList((Object [])r.getArray()));
}
else if (Types.STRUCT == returnType)
{
System.out.println("dbdkj");
currectObject = ((Struct) result).getAttributes();
}
}catch(Exception ex)
{
ex.printStackTrace();
}
if(currectObject != null)
System.out.println("RETURN = class{"+currectObject.getClass().getName()+"} | toString = "+currectObject.toString()+"\n");
return currectObject;
}
示例3: getPseudoColumns
@Override
public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern,
String columnNamePattern) throws SQLException
{
String sql = "select TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, "
+ "CASE " + " WHEN SPANNER_TYPE = 'ARRAY' THEN " + Types.ARRAY + " "
+ " WHEN SPANNER_TYPE = 'BOOL' THEN " + Types.BOOLEAN + " " + " WHEN SPANNER_TYPE = 'BYTES' THEN "
+ Types.BINARY + " " + " WHEN SPANNER_TYPE = 'DATE' THEN " + Types.DATE + " "
+ " WHEN SPANNER_TYPE = 'FLOAT64' THEN " + Types.DOUBLE + " " + " WHEN SPANNER_TYPE = 'INT64' THEN "
+ Types.BIGINT + " " + " WHEN SPANNER_TYPE = 'STRING' THEN " + Types.NVARCHAR + " "
+ " WHEN SPANNER_TYPE = 'STRUCT' THEN " + Types.STRUCT + " "
+ " WHEN SPANNER_TYPE = 'TIMESTAMP' THEN " + Types.TIMESTAMP + " " + "END AS DATA_TYPE, "
+ "0 AS COLUMN_SIZE, NULL AS DECIMAL_DIGITS, 0 AS NUM_PREC_RADIX, 'USAGE_UNKNOWN' AS COLUMN_USAGE, NULL AS REMARKS, 0 AS CHAR_OCTET_LENGTH, IS_NULLABLE "
+ FROM_STATEMENT_WITHOUT_RESULTS;
if (catalog != null)
sql = sql + "AND UPPER(TABLE_CATALOG) like ? ";
if (schemaPattern != null)
sql = sql + "AND UPPER(TABLE_SCHEMA) like ? ";
if (tableNamePattern != null)
sql = sql + "AND UPPER(TABLE_NAME) like ? ";
if (columnNamePattern != null)
sql = sql + "AND UPPER(COLUMN_NAME) LIKE ? ";
sql = sql + "ORDER BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION ";
CloudSpannerPreparedStatement statement = prepareStatement(sql, catalog, schemaPattern, tableNamePattern,
columnNamePattern);
return statement.executeQuery();
}
示例4: isPrecisionRequired
public static boolean isPrecisionRequired(int jdbcType) {
switch (jdbcType) {
case Types.BIGINT:
case Types.BOOLEAN:
case Types.INTEGER:
case Types.SMALLINT:
case Types.TINYINT:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
case Types.DATE:
case Types.TIMESTAMP:
case Types.JAVA_OBJECT:
case Types.LONGVARCHAR:
case Types.LONGVARBINARY:
case Types.BLOB:
case Types.CLOB:
case Types.ARRAY:
case Types.STRUCT:
case Types.DISTINCT:
case Types.REF:
case Types.DATALINK:
return false;
default:
return true;
}
}
示例5: callSampleFunction
/**
* Funcao para invocara as funcaoe simples da base de dado
* Serve para invocar as funcoes que se deve usar o {? = call ...}
* @param functionName O nome da funcao em base de dados que se quer chamar
* @param returnType O que sera retornado por ela
* @param parans Os parametros de entrada na funcao {Atencao que a ordem dos parametros deve ser igual a sua ordem na base de dados}
* @return O retorno sera um objecto do tipo definido
*/
@SuppressWarnings("CallToPrintStackTrace")
public static Object callSampleFunction (String functionName, int returnType, Object ... parans)
{
if(!EstadoConnexao.isValid) return null;
try
{
CallableStatement call;
Object result;
// Criar as interoganocoes necessaria para a invocacao da funcao ex (?, ?, ?, ...) || nada
try (Connection con = new Conexao().getCon())
{
if(con==null)
{
return null;
}
// Criar as interoganocoes necessaria para a invocacao da funcao ex (?, ?, ?, ...) || nada
String interogations = (parans != null && parans.length>0)? createInterogation(parans.length): "";
//Associa ao call e o nome da funcao
String sql = "{? = call "+functionName+interogations+"}";
//Mapear e setar os parametros no call
call = mapParamsType(con, sql, 2, parans);
if (returnType == Call.ARRAY) call.registerOutParameter(1, ARRAY, "TB_ARRAY_STRING");
else if(returnType == Types.STRUCT)
call.registerOutParameter(1,returnType, "TP_OBJECT");
else
call.registerOutParameter(1, returnType);
call.execute();
result = Call.treatReturn(call.getObject(1), returnType);
}call.close();
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例6: getSQLType
/**
* Get the SQLType for the given java.sql.Type type.
*
* @param type the java.sql.Type type specifier
* @return SQLType.the SQLType for this java.sql.Type, or null if it's not recognized
*/
public static SQLType getSQLType(int type) {
switch (type) {
case Types.BIT: return SQLType.BIT;
case Types.TINYINT: return SQLType.TINYINT;
case Types.SMALLINT: return SQLType.SMALLINT;
case Types.INTEGER: return SQLType.INTEGER;
case Types.BIGINT: return SQLType.BIGINT;
case Types.FLOAT: return SQLType.FLOAT;
case Types.REAL: return SQLType.REAL;
case Types.DOUBLE: return SQLType.DOUBLE;
case Types.NUMERIC: return SQLType.NUMERIC;
case Types.DECIMAL: return SQLType.DECIMAL;
case Types.CHAR: return SQLType.CHAR;
case Types.VARCHAR: return SQLType.VARCHAR;
case Types.LONGVARCHAR: return SQLType.LONGVARCHAR;
case Types.DATE: return SQLType.DATE;
case Types.TIME: return SQLType.TIME;
case Types.TIMESTAMP: return SQLType.TIMESTAMP;
case Types.BINARY: return SQLType.BINARY;
case Types.VARBINARY: return SQLType.VARBINARY;
case Types.LONGVARBINARY: return SQLType.LONGVARBINARY;
case Types.NULL: return SQLType.NULL;
case Types.OTHER: return SQLType.OTHER;
case Types.JAVA_OBJECT: return SQLType.JAVA_OBJECT;
case Types.DISTINCT: return SQLType.DISTINCT;
case Types.STRUCT: return SQLType.STRUCT;
case Types.ARRAY: return SQLType.ARRAY;
case Types.BLOB: return SQLType.BLOB;
case Types.CLOB: return SQLType.CLOB;
case Types.REF: return SQLType.REF;
case Types.DATALINK: return SQLType.DATALINK;
case Types.BOOLEAN: return SQLType.BOOLEAN;
case Types.LONGNVARCHAR: return SQLType.LONGVARCHAR;
case Types.NCHAR: return SQLType.CHAR;
case Types.NCLOB: return SQLType.CLOB;
case Types.NVARCHAR: return SQLType.VARCHAR;
case Types.SQLXML: return SQLType.SQLXML;
case Types.ROWID: return SQLType.ROWID;
default:
Logger.getLogger(JDBCUtils.class.getName()).log(Level.WARNING, "Unknown JDBC column type: " + type + ". Returns null.");
return null;
}
}
示例7: getSqlTypeString
/**
* Convert sql types to String for display
*
* @param sqlType the type number from java.sql.Types
* @return the type name
*/
static public String getSqlTypeString(int sqlType) {
switch (sqlType) {
case Types.BIGINT:
return "BIGINT"; //NOI18N
case Types.BINARY:
return "BINARY"; //NOI18N
case Types.BIT:
return "BIT"; //NOI18N
case Types.NCHAR:
return "NCHAR"; //NOI18N
case Types.CHAR:
return "CHAR"; //NOI18N
case Types.DATE:
return "DATE"; //NOI18N
case Types.DECIMAL:
return "DECIMAL"; //NOI18N
case Types.DOUBLE:
return "DOUBLE"; //NOI18N
case Types.FLOAT:
return "FLOAT"; //NOI18N
case Types.INTEGER:
return "INTEGER"; //NOI18N
case Types.LONGVARBINARY:
return "LONGVARBINARY"; //NOI18N
case Types.LONGNVARCHAR:
return "LONGNVARCHAR"; //NOI18N
case Types.LONGVARCHAR:
return "LONGVARCHAR"; //NOI18N
case Types.NULL:
return "NULL"; //NOI18N
case Types.NUMERIC:
return "NUMERIC"; //NOI18N
case Types.OTHER:
return "OTHER"; //NOI18N
case Types.REAL:
return "REAL"; //NOI18N
case Types.SMALLINT:
return "SMALLINT"; //NOI18N
case Types.TIME:
return "TIME"; //NOI18N
case Types.TIMESTAMP:
return "TIMESTAMP"; //NOI18N
case Types.TINYINT:
return "TINYINT"; //NOI18N
case Types.VARBINARY:
return "VARBINARY"; //NOI18N
case Types.NVARCHAR:
return "NVARCHAR";
case Types.VARCHAR:
return "VARCHAR"; //NOI18N
case Types.JAVA_OBJECT:
return "JAVA_OBJECT"; //NOI18N
case Types.DISTINCT:
return "DISTINCT"; //NOI18N
case Types.STRUCT:
return "STRUCT"; //NOI18N
case Types.ARRAY:
return "ARRAY"; //NOI18N
case Types.BLOB:
return "BLOB"; //NOI18N
case Types.NCLOB:
return "NCLOB";
case Types.CLOB:
return "CLOB"; //NOI18N
case Types.REF:
return "REF"; //NOI18N
default:
Logger.getLogger(SQLTypeUtil.class.getName()).log(Level.WARNING, "Unknown JDBC column type: {0}. Returns null.", sqlType);
return "UNKNOWN"; //NOI18N
}
}
示例8: getParameterJavaValue
static public Object getParameterJavaValue(int param_type, String value) throws UnsupportedEncodingException, MalformedURLException, SQLException {
if (value != null) {
switch (param_type) {
case Types.ARRAY:
return value.split(",");
case Types.BIGINT:
return Long.valueOf(value);
case Types.BINARY:
return String.valueOf(value).getBytes("UTF-8");
case Types.BIT:
return Boolean.valueOf(value);
case Types.BLOB:
return value;//connection.createBlob();//
case Types.BOOLEAN:
return Boolean.valueOf(value);
case Types.CHAR:
return String.valueOf(value);
case Types.CLOB:
return value;//connection.createClob();//
case Types.DATALINK:
return new java.net.URL(value);
case Types.DATE:
return java.sql.Date.valueOf(value);
case Types.DECIMAL:
return java.math.BigDecimal.valueOf(Double.valueOf(value));
case Types.DISTINCT:
return value;//Object.class;
case Types.DOUBLE:
return Double.valueOf(value);
case Types.FLOAT:
return Double.valueOf(value);
case Types.INTEGER:
return Integer.valueOf(value, 10);
case Types.JAVA_OBJECT:
return value;//Object.class;
case Types.LONGVARBINARY:
return String.valueOf(value).getBytes("UTF-8");
case Types.LONGVARCHAR:
return String.valueOf(value);
case Types.NCLOB:
return value;//connection.createNClob();//
case Types.NULL:
return null;//Object.class;
case Types.NUMERIC:
return java.math.BigDecimal.valueOf(Double.parseDouble(value));
case Types.NCHAR:
case Types.NVARCHAR:
case Types.LONGNVARCHAR:
return String.valueOf(value);
case Types.OTHER:
return value;//Object.class;
case Types.REAL:
return Float.parseFloat(value);
case Types.REF:
return value;//java.sql.Ref.class;
case Types.ROWID:
return value;//java.sql.RowId.class;
case Types.SMALLINT:
return Short.valueOf(value);
case Types.STRUCT:
return value;//connection.createStruct(typeName, attributes);//
case Types.SQLXML:
return value;//connection.createSQLXML();//
case Types.TIME:
return java.sql.Time.valueOf(value);
case Types.TIMESTAMP:
return java.sql.Timestamp.valueOf(value);
case Types.TINYINT:
return Byte.valueOf(value);
case Types.VARBINARY:
return String.valueOf(value).getBytes("UTF-8");
case Types.VARCHAR:
return String.valueOf(value);
default:
return value;
}
}
return null;
}
示例9: getParameterJavaClass
static public Class<?> getParameterJavaClass(int param_type) {
switch (param_type) {
case Types.ARRAY:
return Object[].class;
case Types.BIGINT:
return Long.class;
case Types.BINARY:
return byte[].class;
case Types.BIT:
return Boolean.class;
case Types.BLOB:
return java.sql.Blob.class;
case Types.BOOLEAN:
return Boolean.class;
case Types.CHAR:
return String.class;
case Types.CLOB:
return java.sql.Clob.class;
case Types.DATALINK:
return java.net.URL.class;
case Types.DATE:
return java.sql.Date.class;
case Types.DECIMAL:
return java.math.BigDecimal.class;
case Types.DISTINCT:
return Object.class;
case Types.DOUBLE:
return Double.class;
case Types.FLOAT:
return Double.class;
case Types.INTEGER:
return Integer.class;
case Types.JAVA_OBJECT:
return Object.class;
case Types.LONGVARBINARY:
return byte[].class;
case Types.LONGVARCHAR:
return String.class;
case Types.NCLOB:
return java.sql.NClob.class;
case Types.NULL:
return Object.class;
case Types.NUMERIC:
return java.math.BigDecimal.class;
case Types.NCHAR:
case Types.NVARCHAR:
case Types.LONGNVARCHAR:
return String.class;
case Types.OTHER:
return Object.class;
case Types.REAL:
return Float.class;
case Types.REF:
return java.sql.Ref.class;
case Types.ROWID:
return java.sql.RowId.class;
case Types.SMALLINT:
return Short.class;
case Types.STRUCT:
return java.sql.Struct.class;
case Types.SQLXML:
return java.sql.SQLXML.class;
case Types.TIME:
return java.sql.Time.class;
case Types.TIMESTAMP:
return java.sql.Timestamp.class;
case Types.TINYINT:
return Byte.class;
case Types.VARBINARY:
return byte[].class;
case Types.VARCHAR:
return String.class;
default:
return Object.class;
}
}
示例10: getSelectClauseNullString
@Override
public String getSelectClauseNullString(int sqlType) {
String v = "null";
switch ( sqlType ) {
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
case Types.NUMERIC:
case Types.DECIMAL:
v = "cast(null as decimal)";
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
v = "cast(null as varchar(255))";
break;
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
v = "cast(null as timestamp)";
break;
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.NULL:
case Types.OTHER:
case Types.JAVA_OBJECT:
case Types.DISTINCT:
case Types.STRUCT:
case Types.ARRAY:
case Types.BLOB:
case Types.CLOB:
case Types.REF:
case Types.DATALINK:
case Types.BOOLEAN:
break;
default:
break;
}
return v;
}
示例11: sqlTypeString
public static String sqlTypeString(int sqlType) {
switch (sqlType) {
case Types.BIT:
return "BIT";
case Types.TINYINT:
return "TINYINT";
case Types.SMALLINT:
return "SMALLINT";
case Types.INTEGER:
return "INTEGER";
case Types.BIGINT:
return "BIGINT";
case Types.FLOAT:
return "FLOAT";
case Types.REAL:
return "REAL";
case Types.DOUBLE:
return "DOUBLE";
case Types.NUMERIC:
return "NUMERIC";
case Types.DECIMAL:
return "DECIMAL";
case Types.CHAR:
return "CHAR";
case Types.VARCHAR:
return "VARCHAR";
case Types.LONGVARCHAR:
return "LONGVARCHAR";
case Types.DATE:
return "DATE";
case Types.TIME:
return "TIME";
case Types.TIMESTAMP:
return "TIMESTAMP";
case Types.BINARY:
return "BINARY";
case Types.VARBINARY:
return "VARBINARY";
case Types.LONGVARBINARY:
return "LONGVARBINARY";
case Types.NULL:
return "NULL";
case Types.OTHER:
return "OTHER";
case Types.JAVA_OBJECT:
return "JAVA_OBJECT";
case Types.DISTINCT:
return "DISTINCT";
case Types.STRUCT:
return "STRUCT";
case Types.ARRAY:
return "ARRAY";
case Types.BLOB:
return "BLOB";
case Types.CLOB:
return "CLOB";
case Types.REF:
return "REF";
case Types.DATALINK:
return "DATALINK";
case Types.BOOLEAN:
return "BOOLEAN";
case Types.ROWID:
return "ROWID";
case Types.NCHAR:
return "NCHAR";
case Types.NVARCHAR:
return "NVARCHAR";
case Types.LONGNVARCHAR:
return "LONGNVARCHAR";
case Types.NCLOB:
return "NCLOB";
case Types.SQLXML:
return "SQLXML";
default:
return "<UNKNOWN>";
}
}
示例12: getValue
private static Object getValue(ResultSet resultSet, int type, int j,
Calendar calendar) throws SQLException {
switch (type) {
case Types.BIGINT:
final long aLong = resultSet.getLong(j + 1);
return aLong == 0 && resultSet.wasNull() ? null : aLong;
case Types.INTEGER:
final int anInt = resultSet.getInt(j + 1);
return anInt == 0 && resultSet.wasNull() ? null : anInt;
case Types.SMALLINT:
final short aShort = resultSet.getShort(j + 1);
return aShort == 0 && resultSet.wasNull() ? null : aShort;
case Types.TINYINT:
final byte aByte = resultSet.getByte(j + 1);
return aByte == 0 && resultSet.wasNull() ? null : aByte;
case Types.DOUBLE:
case Types.FLOAT:
final double aDouble = resultSet.getDouble(j + 1);
return aDouble == 0D && resultSet.wasNull() ? null : aDouble;
case Types.REAL:
final float aFloat = resultSet.getFloat(j + 1);
return aFloat == 0D && resultSet.wasNull() ? null : aFloat;
case Types.DATE:
final Date aDate = resultSet.getDate(j + 1, calendar);
return aDate == null
? null
: (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY);
case Types.TIME:
final Time aTime = resultSet.getTime(j + 1, calendar);
return aTime == null
? null
: (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY);
case Types.TIMESTAMP:
final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar);
return aTimestamp == null ? null : aTimestamp.getTime();
case Types.ARRAY:
final Array array = resultSet.getArray(j + 1);
if (null == array) {
return null;
}
try {
// Recursively extracts an Array using its ResultSet-representation
return extractUsingResultSet(array, calendar);
} catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
// Not every database might implement Array.getResultSet(). This call
// assumes a non-nested array (depends on the db if that's a valid assumption)
return extractUsingArray(array, calendar);
}
case Types.STRUCT:
Struct struct = resultSet.getObject(j + 1, Struct.class);
Object[] attrs = struct.getAttributes();
List<Object> list = new ArrayList<>(attrs.length);
for (Object o : attrs) {
list.add(o);
}
return list;
default:
return resultSet.getObject(j + 1);
}
}
示例13: StructType
@JsonCreator
public StructType(List<ColumnMetaData> columns) {
super(Types.STRUCT, "STRUCT", ColumnMetaData.Rep.OBJECT);
this.columns = columns;
}
示例14: convertValue
private Object convertValue() throws SQLException {
switch (componentType.id) {
case Types.BOOLEAN:
case Types.BIT:
return componentAccessor.getBoolean();
case Types.TINYINT:
return componentAccessor.getByte();
case Types.SMALLINT:
return componentAccessor.getShort();
case Types.INTEGER:
return componentAccessor.getInt();
case Types.BIGINT:
return componentAccessor.getLong();
case Types.FLOAT:
return componentAccessor.getFloat();
case Types.DOUBLE:
return componentAccessor.getDouble();
case Types.ARRAY:
return componentAccessor.getArray();
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.NCHAR:
case Types.LONGNVARCHAR:
return componentAccessor.getString();
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
return componentAccessor.getBytes();
case Types.DECIMAL:
return componentAccessor.getBigDecimal();
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
case Types.STRUCT:
case Types.JAVA_OBJECT:
return componentAccessor.getObject();
default:
throw new IllegalStateException("Unhandled ARRAY component type: " + componentType.rep
+ ", id: " + componentType.id);
}
}