本文整理汇总了Java中java.sql.Types.VARBINARY属性的典型用法代码示例。如果您正苦于以下问题:Java Types.VARBINARY属性的具体用法?Java Types.VARBINARY怎么用?Java Types.VARBINARY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.sql.Types
的用法示例。
在下文中一共展示了Types.VARBINARY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: fromSqlToJava
/**
* Decode the String param type passed by user on client side into a Types
* corresponding value.
*
* @param sqlParamType
* @return
*/
public static int fromSqlToJava(String sqlParamType) {
int javaType = 0;
if (sqlParamType.equals(AceQLTypes.CHARACTER)) {
javaType = Types.CHAR;
} else if (sqlParamType.equals(AceQLTypes.VARCHAR)) {
javaType = Types.VARCHAR;
} else if (sqlParamType.equals(AceQLTypes.LONGVARCHAR)) {
javaType = Types.LONGVARCHAR;
} else if (sqlParamType.equals(AceQLTypes.BIT)) {
javaType = Types.BIT;
} else if (sqlParamType.equals(AceQLTypes.NUMERIC)) {
javaType = Types.NUMERIC;
} else if (sqlParamType.equals(AceQLTypes.TINYINT)) {
javaType = Types.TINYINT;
} else if (sqlParamType.equals(AceQLTypes.SMALLINT)) {
javaType = Types.SMALLINT;
} else if (sqlParamType.equals(AceQLTypes.INTEGER)) {
javaType = Types.INTEGER;
} else if (sqlParamType.equals(AceQLTypes.BIGINT)) {
javaType = Types.BIGINT;
} else if (sqlParamType.equals(AceQLTypes.REAL)) {
javaType = Types.REAL;
} else if (sqlParamType.equals(AceQLTypes.FLOAT)) {
javaType = Types.FLOAT;
} else if (sqlParamType.equals(AceQLTypes.DOUBLE_PRECISION)) {
javaType = Types.DOUBLE;
} else if (sqlParamType.equals(AceQLTypes.DATE)) {
javaType = Types.DATE;
} else if (sqlParamType.equals(AceQLTypes.TIME)) {
javaType = Types.TIME;
} else if (sqlParamType.equals(AceQLTypes.TIMESTAMP)) {
javaType = Types.TIMESTAMP;
} else if (sqlParamType.equals(AceQLTypes.BINARY)) {
javaType = Types.BINARY;
} else if (sqlParamType.equals(AceQLTypes.VARBINARY)) {
javaType = Types.VARBINARY;
} else if (sqlParamType.equals(AceQLTypes.DATE)) {
javaType = Types.LONGVARBINARY;
} else if (sqlParamType.equals(AceQLTypes.BLOB)) {
javaType = Types.BLOB;
} else if (sqlParamType.equals(AceQLTypes.CLOB)) {
javaType = Types.CLOB;
} else if (sqlParamType.startsWith("TYPE_NULL")) {
String javaTypeStr = StringUtils.substringAfter(sqlParamType,
"TYPE_NULL");
javaType = Integer.parseInt(javaTypeStr);
} else {
throw new IllegalArgumentException(
"Unsuported data type for null setting: " + sqlParamType);
}
return javaType;
}
示例4: 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"}
};
}
示例5: getTypeClass
protected static Class<? extends Object> getTypeClass(DBColumn col) {
int colType = col.getJdbcType();
if (colType == Types.BIT && col.getPrecision() <= 1) {
colType = Types.BOOLEAN;
}
switch (colType) {
case Types.BOOLEAN:
return Boolean.class;
case Types.TIME:
return Time.class;
case Types.DATE:
return Date.class;
case Types.TIMESTAMP:
case DBReadWriteHelper.SQL_TYPE_ORACLE_TIMESTAMP:
case DBReadWriteHelper.SQL_TYPE_ORACLE_TIMESTAMP_WITH_TZ:
return Timestamp.class;
case Types.BIGINT:
return BigInteger.class;
case Types.DOUBLE:
return Double.class;
case Types.FLOAT:
case Types.REAL:
return Float.class;
case Types.DECIMAL:
case Types.NUMERIC:
return BigDecimal.class;
case Types.INTEGER:
case Types.SMALLINT:
case Types.TINYINT:
return Long.class;
case Types.CHAR:
case Types.VARCHAR:
case Types.NCHAR:
case Types.NVARCHAR:
case Types.ROWID:
return String.class;
case Types.BIT:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.BLOB:
return Blob.class;
case Types.LONGVARCHAR:
case Types.LONGNVARCHAR:
case Types.CLOB:
case Types.NCLOB: /*NCLOB */
return Clob.class;
case Types.OTHER:
default:
return Object.class;
}
}
示例6: 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);
}
}
示例7: getFieldType
/**
* 根据Types获取字段类型
*
* @see Types
* @return 对应字段的java类型
*/
public static FieldType getFieldType(Integer sqlType) {
FieldType fieldType = sqlTypes.get("UNKNOWN");
if (sqlType == null) {
return fieldType;
}
// https://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/getstart/mapping.html
if (sqlType == Types.INTEGER) {
fieldType = sqlTypes.get("INTEGER");
} else if (sqlType == Types.VARCHAR) {
fieldType = sqlTypes.get("STRING");
} else if (sqlType == Types.CHAR) {
fieldType = sqlTypes.get("STRING");
} else if (sqlType == Types.LONGVARCHAR) {
fieldType = sqlTypes.get("STRING");
} else if (sqlType == Types.NVARCHAR) {
fieldType = sqlTypes.get("STRING");
} else if (sqlType == Types.NCHAR) {
fieldType = sqlTypes.get("STRING");
} else if (sqlType == Types.LONGNVARCHAR) {
fieldType = sqlTypes.get("STRING");
} else if (sqlType == Types.NUMERIC) {
fieldType = sqlTypes.get("DECIMAL");
} else if (sqlType == Types.DECIMAL) {
fieldType = sqlTypes.get("DECIMAL");
} else if (sqlType == Types.BIT) {
fieldType = sqlTypes.get("BOOLEAN");
} else if (sqlType == Types.BOOLEAN) {
fieldType = sqlTypes.get("BOOLEAN");
} else if (sqlType == Types.TINYINT) {
fieldType = sqlTypes.get("INTEGER");
} else if (sqlType == Types.SMALLINT) {
fieldType = sqlTypes.get("INTEGER");
} else if (sqlType == Types.BIGINT) {
fieldType = sqlTypes.get("BIGINT");
} else if (sqlType == Types.REAL) {
fieldType = sqlTypes.get("REAL");
} else if (sqlType == Types.FLOAT) {
fieldType = sqlTypes.get("FLOAT");
} else if (sqlType == Types.DOUBLE) {
fieldType = sqlTypes.get("DOUBLE");
} else if (sqlType == Types.DATE) {
// java.sql.Date ?
fieldType = sqlTypes.get("DATE");
} else if (sqlType == Types.TIME) {
// java.sql.Time ?
fieldType = sqlTypes.get("TIME");
} else if (sqlType == Types.TIMESTAMP) {
// java.sql.Timestamp ?
fieldType = sqlTypes.get("TIMESTAMP");
} else if (sqlType == Types.BINARY
|| sqlType == Types.VARBINARY) {
fieldType = sqlTypes.get("BINARY");
} else if (sqlType == Types.CLOB) {
fieldType = sqlTypes.get("CLOB");
} else if (sqlType == Types.BLOB
|| sqlType == Types.LONGVARBINARY) {
fieldType = sqlTypes.get("BLOB");
} else {
// DISTINCT, ARRAY, STRUCT, REF, JAVA_OBJECT.
return fieldType;
}
return fieldType;
}
示例8: testAllFieldsForNotNull
@SuppressWarnings("deprecation")
private void testAllFieldsForNotNull(ResultSet rsToTest, List<Boolean> wasDatetimeTypeList) throws Exception {
ResultSetMetaData rsmd = this.rs.getMetaData();
int numCols = rsmd.getColumnCount();
while (rsToTest.next()) {
for (int i = 0; i < numCols - 1; i++) {
boolean wasDatetimeType = wasDatetimeTypeList.get(i).booleanValue();
String typeName = rsmd.getColumnTypeName(i + 1);
int sqlType = rsmd.getColumnType(i + 1);
if (!"BIT".equalsIgnoreCase(typeName) && sqlType != Types.BINARY && sqlType != Types.VARBINARY && sqlType != Types.LONGVARBINARY) {
if (!wasDatetimeType) {
assertEquals(false, rsToTest.getBoolean(i + 1));
assertTrue(!rsToTest.wasNull());
assertEquals(0, rsToTest.getDouble(i + 1), 0 /* delta */);
assertTrue(!rsToTest.wasNull());
assertEquals(0, rsToTest.getFloat(i + 1), 0 /* delta */);
assertTrue(!rsToTest.wasNull());
assertEquals(0, rsToTest.getInt(i + 1));
assertTrue(!rsToTest.wasNull());
assertEquals(0, rsToTest.getLong(i + 1));
assertTrue(!rsToTest.wasNull());
assertEquals(0, rsToTest.getByte(i + 1));
assertTrue(!rsToTest.wasNull());
assertEquals(0, rsToTest.getShort(i + 1));
assertTrue(!rsToTest.wasNull());
}
assertNotNull(rsToTest.getObject(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getString(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getAsciiStream(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getBinaryStream(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getBlob(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getBytes(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getCharacterStream(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getClob(i + 1));
assertTrue(!rsToTest.wasNull());
String columnClassName = rsmd.getColumnClassName(i + 1);
boolean canBeUsedAsDate = !("java.lang.Boolean".equals(columnClassName) || "java.lang.Double".equals(columnClassName)
|| "java.lang.Float".equals(columnClassName) || "java.lang.Real".equals(columnClassName)
|| "java.math.BigDecimal".equals(columnClassName));
if (canBeUsedAsDate) {
assertNotNull(rsToTest.getDate(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getTime(i + 1));
assertTrue(!rsToTest.wasNull());
assertNotNull(rsToTest.getTimestamp(i + 1));
assertTrue(!rsToTest.wasNull());
}
assertNotNull(rsToTest.getUnicodeStream(i + 1));
assertTrue(!rsToTest.wasNull());
try {
assertNotNull(rsToTest.getURL(i + 1));
} catch (SQLException sqlEx) {
assertTrue(sqlEx.getMessage().indexOf("URL") != -1);
}
assertTrue(!rsToTest.wasNull());
}
}
}
}
示例9: 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;
}
// fallthrough
default:
int sqlType = field.getSQLType();
if (sqlType == Types.VARBINARY || sqlType == Types.BINARY) {
return (byte[]) value;
}
return getBytesFromString(getNativeString(columnIndex));
}
}
示例10: testBug25715
/**
* Tests fix for BUG#25715 - CallableStatements with OUT/INOUT parameters
* that are "binary" have extra 7 bytes (which happens to be the _binary
* introducer!)
*
* @throws Exception
* if the test fails.
*/
public void testBug25715() throws Exception {
if (!serverSupportsStoredProcedures()) {
return; // no stored procs
}
createProcedure("spbug25715", "(INOUT mblob MEDIUMBLOB) BEGIN SELECT 1 FROM DUAL WHERE 1=0;\nEND");
CallableStatement cstmt = null;
try {
cstmt = this.conn.prepareCall("{call spbug25715(?)}");
byte[] buf = new byte[65];
for (int i = 0; i < 65; i++) {
buf[i] = 1;
}
int il = buf.length;
int[] typesToTest = new int[] { Types.BIT, Types.BINARY, Types.BLOB, Types.JAVA_OBJECT, Types.LONGVARBINARY, Types.VARBINARY };
for (int i = 0; i < typesToTest.length; i++) {
cstmt.setBinaryStream("mblob", new ByteArrayInputStream(buf), buf.length);
cstmt.registerOutParameter("mblob", typesToTest[i]);
cstmt.executeUpdate();
InputStream is = cstmt.getBlob("mblob").getBinaryStream();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int bytesRead = 0;
byte[] readBuf = new byte[256];
while ((bytesRead = is.read(readBuf)) != -1) {
bOut.write(readBuf, 0, bytesRead);
}
byte[] fromSelectBuf = bOut.toByteArray();
int ol = fromSelectBuf.length;
assertEquals(il, ol);
}
cstmt.close();
} finally {
if (cstmt != null) {
cstmt.close();
}
}
}
示例11: 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));
}
示例12: javaTypeMysql
public static int javaTypeMysql(int javaType) {
switch (javaType) {
case Types.NUMERIC:
return MysqlDefs.FIELD_TYPE_DECIMAL;
case Types.DECIMAL:
return MysqlDefs.FIELD_TYPE_NEW_DECIMAL;
case Types.TINYINT:
return MysqlDefs.FIELD_TYPE_TINY;
case Types.SMALLINT:
return MysqlDefs.FIELD_TYPE_SHORT;
case Types.INTEGER:
return MysqlDefs.FIELD_TYPE_LONG;
case Types.REAL:
return MysqlDefs.FIELD_TYPE_FLOAT;
case Types.DOUBLE:
return MysqlDefs.FIELD_TYPE_DOUBLE;
case Types.NULL:
return MysqlDefs.FIELD_TYPE_NULL;
case Types.TIMESTAMP:
return MysqlDefs.FIELD_TYPE_TIMESTAMP;
case Types.BIGINT:
return MysqlDefs.FIELD_TYPE_LONGLONG;
case Types.DATE:
return MysqlDefs.FIELD_TYPE_DATE;
case Types.TIME:
return MysqlDefs.FIELD_TYPE_TIME;
case Types.VARBINARY:
return MysqlDefs.FIELD_TYPE_TINY_BLOB;
case Types.LONGVARBINARY:
return MysqlDefs.FIELD_TYPE_BLOB;
//对应sqlserver的image类型
case 27:
return MysqlDefs.FIELD_TYPE_BLOB;
case Types.VARCHAR:
return MysqlDefs.FIELD_TYPE_VAR_STRING;
case Types.CHAR:
return MysqlDefs.FIELD_TYPE_STRING;
case Types.BINARY:
return MysqlDefs.FIELD_TYPE_GEOMETRY;
case Types.BIT:
return MysqlDefs.FIELD_TYPE_BIT;
case Types.CLOB:
return MysqlDefs.FIELD_TYPE_VAR_STRING;
case Types.BLOB:
return MysqlDefs.FIELD_TYPE_BLOB;
//修改by [email protected]
// 当jdbc连接非mysql的数据库时,需要把对应类型映射为mysql的类型,否则应用端会出错
case Types.NVARCHAR:
return MysqlDefs.FIELD_TYPE_VAR_STRING;
case Types.NCHAR:
return MysqlDefs.FIELD_TYPE_STRING;
case Types.NCLOB:
return MysqlDefs.FIELD_TYPE_VAR_STRING;
case Types.LONGNVARCHAR:
return MysqlDefs.FIELD_TYPE_VAR_STRING;
default:
return MysqlDefs.FIELD_TYPE_VAR_STRING; //其他未知类型返回字符类型
// return Types.VARCHAR;
}
}
示例13: getValue
private static Value getValue(String columnName,int type,ResultSet rs)
{
Value value = new Value(type);
try
{
switch(type)
{
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.NCHAR:
case Types.NVARCHAR:
case Types.LONGNVARCHAR:
value.setString_value(rs.getString(columnName));
break;
case Types.FLOAT:
case Types.DOUBLE:
value.setDouble_value(rs.getDouble(columnName));
break;
case Types.INTEGER:
case Types.SMALLINT:
value.setInt_value(rs.getInt(columnName));
break;
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
value.setBytes_value(rs.getBytes(columnName));
break;
case Types.BLOB:
value.setBlob_value(rs.getBlob(columnName));
break;
case Types.NUMERIC:
case Types.DECIMAL:
value.setBigdecimal_value(rs.getBigDecimal(columnName));
break;
case Types.BIT:
case Types.BOOLEAN:
value.setBoolean_value(rs.getBoolean(columnName));
break;
case Types.TINYINT:
value.setByte_value(rs.getByte(columnName));
break;
case Types.BIGINT:
value.setLong_value(rs.getLong(columnName));
break;
case Types.REAL:
value.setFloat_value(rs.getFloat(columnName));
break;
case Types.DATE:
value.setDate_value(rs.getDate(columnName));
break;
case Types.TIME:
case Types.TIMESTAMP:
value.setTime_value(rs.getTime(columnName));
break;
default:
value.setObject_value(rs.getObject(columnName));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
DBCException.logException(DBCException.E_ResultSet, e);
return null;
}
return value;
}
示例14: 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;
}
示例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();
}
}
}
}
}
}
}