本文整理汇总了Java中java.sql.Types.BINARY属性的典型用法代码示例。如果您正苦于以下问题:Java Types.BINARY属性的具体用法?Java Types.BINARY怎么用?Java Types.BINARY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.sql.Types
的用法示例。
在下文中一共展示了Types.BINARY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getColumnDisplaySize
@Override
public int getColumnDisplaySize(int column) throws SQLException
{
int colType = getColumnType(column);
switch (colType)
{
case Types.ARRAY:
return 50;
case Types.BOOLEAN:
return 5;
case Types.BINARY:
return 50;
case Types.DATE:
return 10;
case Types.DOUBLE:
return 14;
case Types.BIGINT:
return 10;
case Types.NVARCHAR:
return 50;
case Types.TIMESTAMP:
return 16;
}
return 10;
}
示例2: setSerializableObject
/**
* Sets the value for the placeholder as a serialized Java object (used by
* various forms of setObject()
*
* @param parameterIndex
* @param parameterObj
*
* @throws SQLException
*/
private final void setSerializableObject(int parameterIndex, Object parameterObj) throws SQLException {
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
ObjectOutputStream objectOut = new ObjectOutputStream(bytesOut);
objectOut.writeObject(parameterObj);
objectOut.flush();
objectOut.close();
bytesOut.flush();
bytesOut.close();
byte[] buf = bytesOut.toByteArray();
ByteArrayInputStream bytesIn = new ByteArrayInputStream(buf);
setBinaryStream(parameterIndex, bytesIn, buf.length);
this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = Types.BINARY;
} catch (Exception ex) {
SQLException sqlEx = SQLError.createSQLException(Messages.getString("PreparedStatement.54") + ex.getClass().getName(),
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor());
sqlEx.initCause(ex);
throw sqlEx;
}
}
示例3: Field
/**
* Used by prepared statements to re-use result set data conversion methods
* when generating bound parmeter retrieval instance for statement
* interceptors.
*
* @param tableName
* not used
* @param columnName
* not used
* @param charsetIndex
* the MySQL collation/character set index
* @param jdbcType
* from java.sql.Types
* @param length
* length in characters or bytes (for BINARY data).
*/
Field(String tableName, String columnName, int charsetIndex, int jdbcType, int length) {
this.tableName = tableName;
this.name = columnName;
this.length = length;
this.sqlType = jdbcType;
this.colFlag = 0;
this.colDecimals = 0;
this.collationIndex = charsetIndex;
this.valueNeedsQuoting = determineNeedsQuoting();
switch (this.sqlType) {
case Types.BINARY:
case Types.VARBINARY:
this.colFlag |= 128;
this.colFlag |= 16;
break;
}
}
示例4: isBinaryColumn
/**
* return true if the column is a binary type
*
* @param resultSet
* used to get back the Connection for PostgreSQL meta query
* @param columnType
* the sql column type
* @param columnName
* the sql column name
* @param columnTable
* the table name of the column
* @return true if it's a binary type
*/
private boolean isBinaryColumn(ResultSet resultSet, int columnType,
String columnName, String columnTable)
throws SQLException, IOException {
if (columnType == Types.BINARY || columnType == Types.VARBINARY
|| columnType == Types.LONGVARBINARY
|| columnType == Types.BLOB) {
return true;
} else {
// Special treatment for PostgreSQL OID which Java long/BIGINT type
if (isPostgreSQL && columnType == Types.BIGINT) {
if (typeBigIntColumnNames == null) {
Connection connection = resultSet.getStatement()
.getConnection();
typeBigIntColumnNames = PostgreSqlUtil
.getTypeBigIntColumnNames(connection);
}
if (typeBigIntColumnNames
.contains(columnName.trim().toLowerCase())) {
return true;
}
}
return false;
}
}
示例5: getNativeBinaryStream
/**
* A column value can also be retrieved as a binary stream. This method is
* suitable for retrieving LONGVARBINARY values.
*
* @param columnIndex
* the first column is 1, the second is 2...
*
* @return a Java InputStream that delivers the database column value as a
* stream of bytes. If the value is SQL NULL, then the result is
* null
*
* @exception SQLException
* if a database access error occurs
*
* @see getAsciiStream
* @see getUnicodeStream
*/
protected InputStream getNativeBinaryStream(int columnIndex) throws SQLException {
checkRowPos();
int columnIndexMinusOne = columnIndex - 1;
if (this.thisRow.isNull(columnIndexMinusOne)) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
switch (this.fields[columnIndexMinusOne].getSQLType()) {
case Types.BIT:
case Types.BINARY:
case Types.VARBINARY:
case Types.BLOB:
case Types.LONGVARBINARY:
return this.thisRow.getBinaryInputStream(columnIndexMinusOne);
}
byte[] b = getNativeBytes(columnIndex, false);
if (b != null) {
return new ByteArrayInputStream(b);
}
return null;
}
示例6: finagle
ColumnMetaData finagle(ColumnMetaData column) {
switch (column.type.rep) {
case BYTE:
case PRIMITIVE_BYTE:
case DOUBLE:
case PRIMITIVE_DOUBLE:
case FLOAT:
case PRIMITIVE_FLOAT:
case INTEGER:
case PRIMITIVE_INT:
case SHORT:
case PRIMITIVE_SHORT:
case LONG:
case PRIMITIVE_LONG:
return column.setRep(ColumnMetaData.Rep.NUMBER);
default:
// continue
break;
}
switch (column.type.id) {
case Types.VARBINARY:
case Types.BINARY:
switch (getSerializationType()) {
case JSON:
return column.setRep(ColumnMetaData.Rep.STRING);
case PROTOBUF:
return column;
default:
throw new IllegalStateException("Unhadled case statement");
}
case Types.DECIMAL:
case Types.NUMERIC:
return column.setRep(ColumnMetaData.Rep.NUMBER);
default:
return column;
}
}
示例7: columnClassNames
@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
return new Object[][]{
{Types.CHAR, "java.lang.String"},
{Types.NCHAR, "java.lang.String"},
{Types.VARCHAR, "java.lang.String"},
{Types.NVARCHAR, "java.lang.String"},
{Types.LONGVARCHAR, "java.lang.String"},
{Types.LONGNVARCHAR, "java.lang.String"},
{Types.NUMERIC, "java.math.BigDecimal"},
{Types.DECIMAL, "java.math.BigDecimal"},
{Types.BIT, "java.lang.Boolean"},
{Types.TINYINT, "java.lang.Byte"},
{Types.SMALLINT, "java.lang.Short"},
{Types.INTEGER, "java.lang.Integer"},
{Types.FLOAT, "java.lang.Double"},
{Types.DOUBLE, "java.lang.Double"},
{Types.BINARY, "byte[]"},
{Types.VARBINARY, "byte[]"},
{Types.LONGVARBINARY, "byte[]"},
{Types.DATE, "java.sql.Date"},
{Types.TIME, "java.sql.Time"},
{Types.TIMESTAMP, "java.sql.Timestamp"},
{Types.CLOB, "java.sql.Clob"},
{Types.BLOB, "java.sql.Blob"}
};
}
示例8: getActualDataSize
public int getActualDataSize(int colType, Object data)
{
int size = 0;
switch (colType)
{
case Types.ARRAY:
break;
case Types.BOOLEAN:
size = 1;
break;
case Types.BINARY:
if (data != null && byte[].class.equals(data.getClass()))
size = ((byte[]) data).length;
else if (data != null && ByteArray.class.equals(data))
size = ((ByteArray) data).length();
break;
case Types.DATE:
size = 4;
break;
case Types.DOUBLE:
size = 8;
break;
case Types.BIGINT:
size = 8;
break;
case Types.NVARCHAR:
if (data != null && String.class.equals(data.getClass()))
size = ((String) data).getBytes().length;
break;
case Types.TIMESTAMP:
size = 12;
break;
}
return size;
}
示例9: mysqlToJavaType
/**
* Maps the given MySQL type to the correct JDBC type.
*/
static int mysqlToJavaType(String mysqlType) {
if (mysqlType.equalsIgnoreCase("BIT")) {
return mysqlToJavaType(FIELD_TYPE_BIT);
} else if (mysqlType.equalsIgnoreCase("TINYINT")) {
return mysqlToJavaType(FIELD_TYPE_TINY);
} else if (mysqlType.equalsIgnoreCase("SMALLINT")) {
return mysqlToJavaType(FIELD_TYPE_SHORT);
} else if (mysqlType.equalsIgnoreCase("MEDIUMINT")) {
return mysqlToJavaType(FIELD_TYPE_INT24);
} else if (mysqlType.equalsIgnoreCase("INT") || mysqlType.equalsIgnoreCase("INTEGER")) {
return mysqlToJavaType(FIELD_TYPE_LONG);
} else if (mysqlType.equalsIgnoreCase("BIGINT")) {
return mysqlToJavaType(FIELD_TYPE_LONGLONG);
} else if (mysqlType.equalsIgnoreCase("INT24")) {
return mysqlToJavaType(FIELD_TYPE_INT24);
} else if (mysqlType.equalsIgnoreCase("REAL")) {
return mysqlToJavaType(FIELD_TYPE_DOUBLE);
} else if (mysqlType.equalsIgnoreCase("FLOAT")) {
return mysqlToJavaType(FIELD_TYPE_FLOAT);
} else if (mysqlType.equalsIgnoreCase("DECIMAL")) {
return mysqlToJavaType(FIELD_TYPE_DECIMAL);
} else if (mysqlType.equalsIgnoreCase("NUMERIC")) {
return mysqlToJavaType(FIELD_TYPE_DECIMAL);
} else if (mysqlType.equalsIgnoreCase("DOUBLE")) {
return mysqlToJavaType(FIELD_TYPE_DOUBLE);
} else if (mysqlType.equalsIgnoreCase("CHAR")) {
return mysqlToJavaType(FIELD_TYPE_STRING);
} else if (mysqlType.equalsIgnoreCase("VARCHAR")) {
return mysqlToJavaType(FIELD_TYPE_VAR_STRING);
} else if (mysqlType.equalsIgnoreCase("DATE")) {
return mysqlToJavaType(FIELD_TYPE_DATE);
} else if (mysqlType.equalsIgnoreCase("TIME")) {
return mysqlToJavaType(FIELD_TYPE_TIME);
} else if (mysqlType.equalsIgnoreCase("YEAR")) {
return mysqlToJavaType(FIELD_TYPE_YEAR);
} else if (mysqlType.equalsIgnoreCase("TIMESTAMP")) {
return mysqlToJavaType(FIELD_TYPE_TIMESTAMP);
} else if (mysqlType.equalsIgnoreCase("DATETIME")) {
return mysqlToJavaType(FIELD_TYPE_DATETIME);
} else if (mysqlType.equalsIgnoreCase("TINYBLOB")) {
return java.sql.Types.BINARY;
} else if (mysqlType.equalsIgnoreCase("BLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("MEDIUMBLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("LONGBLOB")) {
return java.sql.Types.LONGVARBINARY;
} else if (mysqlType.equalsIgnoreCase("TINYTEXT")) {
return java.sql.Types.VARCHAR;
} else if (mysqlType.equalsIgnoreCase("TEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("MEDIUMTEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("LONGTEXT")) {
return java.sql.Types.LONGVARCHAR;
} else if (mysqlType.equalsIgnoreCase("ENUM")) {
return mysqlToJavaType(FIELD_TYPE_ENUM);
} else if (mysqlType.equalsIgnoreCase("SET")) {
return mysqlToJavaType(FIELD_TYPE_SET);
} else if (mysqlType.equalsIgnoreCase("GEOMETRY")) {
return mysqlToJavaType(FIELD_TYPE_GEOMETRY);
} else if (mysqlType.equalsIgnoreCase("BINARY")) {
return Types.BINARY; // no concrete type on the wire
} else if (mysqlType.equalsIgnoreCase("VARBINARY")) {
return Types.VARBINARY; // no concrete type on the wire
} else if (mysqlType.equalsIgnoreCase("BIT")) {
return mysqlToJavaType(FIELD_TYPE_BIT);
} else if (mysqlType.equalsIgnoreCase("JSON")) {
return mysqlToJavaType(FIELD_TYPE_JSON);
}
// Punt
return java.sql.Types.OTHER;
}
示例10: getNativeBytes
/**
* Get the value of a column in the current row as a Java byte array.
*
* <p>
* <b>Be warned</b> If the blob is huge, then you may run out of memory.
* </p>
*
* @param columnIndex
* the first column is 1, the second is 2, ...
*
* @return the column value; if the value is SQL NULL, the result is null
*
* @exception SQLException
* if a database access error occurs
*/
protected byte[] getNativeBytes(int columnIndex, boolean noConversion) throws SQLException {
checkRowPos();
checkColumnBounds(columnIndex);
Object value = this.thisRow.getColumnValue(columnIndex - 1);
if (value == null) {
this.wasNullFlag = true;
} else {
this.wasNullFlag = false;
}
if (this.wasNullFlag) {
return null;
}
Field field = this.fields[columnIndex - 1];
int mysqlType = field.getMysqlType();
// Workaround for emulated locators in servers > 4.1, as server returns SUBSTRING(blob) as STRING type...
if (noConversion) {
mysqlType = MysqlDefs.FIELD_TYPE_BLOB;
}
switch (mysqlType) {
case MysqlDefs.FIELD_TYPE_TINY_BLOB:
case MysqlDefs.FIELD_TYPE_MEDIUM_BLOB:
case MysqlDefs.FIELD_TYPE_LONG_BLOB:
case MysqlDefs.FIELD_TYPE_BLOB:
case MysqlDefs.FIELD_TYPE_BIT:
return (byte[]) value;
case MysqlDefs.FIELD_TYPE_STRING:
case MysqlDefs.FIELD_TYPE_VARCHAR:
case MysqlDefs.FIELD_TYPE_VAR_STRING:
if (value instanceof byte[]) {
return (byte[]) value;
}
break;
default:
break;
}
int sqlType = field.getSQLType();
if (sqlType == Types.VARBINARY || sqlType == Types.BINARY) {
return (byte[]) value;
}
return getBytesFromString(getNativeString(columnIndex));
}
示例11: toAvroType
/**
* Resolve a database-specific type to Avro data type.
* @param sqlType sql type
* @return avro type
*/
public Type toAvroType(int sqlType) {
switch (sqlType) {
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
return Type.INT;
case Types.BIGINT:
return Type.LONG;
case Types.BIT:
case Types.BOOLEAN:
return Type.BOOLEAN;
case Types.REAL:
return Type.FLOAT;
case Types.FLOAT:
case Types.DOUBLE:
return Type.DOUBLE;
case Types.NUMERIC:
case Types.DECIMAL:
return Type.STRING;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.LONGNVARCHAR:
case Types.NVARCHAR:
case Types.NCHAR:
return Type.STRING;
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
return Type.LONG;
case Types.BLOB:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
return Type.BYTES;
default:
throw new IllegalArgumentException("Cannot convert SQL type "
+ sqlType);
}
}
示例12: 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
}
}
示例13: classToJdbcType
/**
* Get the SQL type which corresponds to given Java type.
* @param type Java type
* @return SQL type
*/
public static int classToJdbcType(Class<?> type) {
if (type == null) {
return Types.NULL;
}
if (String.class.isAssignableFrom(type)) {
return Types.VARCHAR;
}
if (TypeUtils.isBoolean(type)) {
return Types.BOOLEAN;
}
if (TypeUtils.isInteger(type)) {
return Types.INTEGER;
}
if (TypeUtils.isLong(type)) {
return Types.BIGINT;
}
if (TypeUtils.isDouble(type) || TypeUtils.isFloat(type) || TypeUtils.isBigDecimal(type)) {
return Types.DECIMAL;
}
if (TypeUtils.isShort(type)) {
return Types.SMALLINT;
}
if (TypeUtils.isByte(type)) {
return Types.TINYINT;
}
if (TypeUtils.isNumber(type)) {
return Types.NUMERIC;
}
if (type == byte[].class) {
return Types.BINARY;
}
if (TypeUtils.isDate(type) || TypeUtils.isCalendar(type) || java.sql.Date.class.isAssignableFrom(type)
|| LocalDate.class.isAssignableFrom(type)) {
return Types.DATE;
}
if (LocalTime.class.isAssignableFrom(type) || java.sql.Time.class.isAssignableFrom(type)) {
return Types.TIME;
}
if (LocalDateTime.class.isAssignableFrom(type) || java.sql.Timestamp.class.isAssignableFrom(type)) {
return Types.TIMESTAMP;
}
if (ZonedDateTime.class.isAssignableFrom(type)) {
return Types.TIMESTAMP_WITH_TIMEZONE;
}
return Types.OTHER;
}
示例14: getEstimatedRowSizeInCloudSpanner
/**
* @param connection
* The connection to use to estimate the row size
* @param catalog
* The catalog of the table
* @param schemaPattern
* The schema of the table
* @param tableNamePattern
* The name of the table
* @param columnNamePattern
* The name of the column(s) to check
* @return The estimated size in bytes of one row of the specified columns
* of the specified table
*/
public int getEstimatedRowSizeInCloudSpanner(Connection connection, String catalog, String schemaPattern,
String tableNamePattern, String columnNamePattern) throws SQLException
{
// There's an 8 bytes storage overhead for each column
int totalSize = 8;
try (ResultSet rs = connection.getMetaData().getColumns(catalog, schemaPattern, tableNamePattern,
columnNamePattern))
{
while (rs.next())
{
long colLength = rs.getLong("COLUMN_SIZE");
int colType = rs.getInt("DATA_TYPE");
switch (colType)
{
case Types.ARRAY:
break;
case Types.BOOLEAN:
totalSize += 1;
break;
case Types.BINARY:
totalSize += colLength;
break;
case Types.DATE:
totalSize += 4;
break;
case Types.DOUBLE:
totalSize += 8;
break;
case Types.BIGINT:
totalSize += 8;
break;
case Types.NVARCHAR:
totalSize += colLength * 2;
break;
case Types.TIMESTAMP:
totalSize += 12;
break;
}
}
}
return totalSize;
}
示例15: setInOutParamsOnServer
private void setInOutParamsOnServer() throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
if (this.paramInfo.numParameters > 0) {
for (Iterator<CallableStatementParam> paramIter = this.paramInfo.iterator(); paramIter.hasNext();) {
CallableStatementParam inParamInfo = paramIter.next();
//Fix for 5.5+
if (inParamInfo.isOut && inParamInfo.isIn) {
if ((inParamInfo.paramName == null) && (hasParametersView())) {
inParamInfo.paramName = "nullnp" + inParamInfo.index;
}
String inOutParameterName = mangleParameterName(inParamInfo.paramName);
StringBuilder queryBuf = new StringBuilder(4 + inOutParameterName.length() + 1 + 1);
queryBuf.append("SET ");
queryBuf.append(inOutParameterName);
queryBuf.append("=?");
PreparedStatement setPstmt = null;
try {
setPstmt = ((Wrapper) this.connection.clientPrepareStatement(queryBuf.toString())).unwrap(PreparedStatement.class);
if (this.isNull[inParamInfo.index]) {
setPstmt.setBytesNoEscapeNoQuotes(1, "NULL".getBytes());
} else {
byte[] parameterAsBytes = getBytesRepresentation(inParamInfo.index);
if (parameterAsBytes != null) {
if (parameterAsBytes.length > 8 && parameterAsBytes[0] == '_' && parameterAsBytes[1] == 'b' && parameterAsBytes[2] == 'i'
&& parameterAsBytes[3] == 'n' && parameterAsBytes[4] == 'a' && parameterAsBytes[5] == 'r'
&& parameterAsBytes[6] == 'y' && parameterAsBytes[7] == '\'') {
setPstmt.setBytesNoEscapeNoQuotes(1, parameterAsBytes);
} else {
int sqlType = inParamInfo.desiredJdbcType;
switch (sqlType) {
case Types.BIT:
case Types.BINARY:
case Types.BLOB:
case Types.JAVA_OBJECT:
case Types.LONGVARBINARY:
case Types.VARBINARY:
setPstmt.setBytes(1, parameterAsBytes);
break;
default:
// the inherited PreparedStatement methods have already escaped and quoted these parameters
setPstmt.setBytesNoEscape(1, parameterAsBytes);
}
}
} else {
setPstmt.setNull(1, Types.NULL);
}
}
setPstmt.executeUpdate();
} finally {
if (setPstmt != null) {
setPstmt.close();
}
}
}
}
}
}
}