本文整理汇总了Java中java.sql.Types.CHAR属性的典型用法代码示例。如果您正苦于以下问题:Java Types.CHAR属性的具体用法?Java Types.CHAR怎么用?Java Types.CHAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.sql.Types
的用法示例。
在下文中一共展示了Types.CHAR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndexInfoFields
protected Field[] createIndexInfoFields() {
Field[] fields = new Field[13];
fields[0] = new Field("", "TABLE_CAT", Types.CHAR, 255);
fields[1] = new Field("", "TABLE_SCHEM", Types.CHAR, 0);
fields[2] = new Field("", "TABLE_NAME", Types.CHAR, 255);
fields[3] = new Field("", "NON_UNIQUE", Types.BOOLEAN, 4);
fields[4] = new Field("", "INDEX_QUALIFIER", Types.CHAR, 1);
fields[5] = new Field("", "INDEX_NAME", Types.CHAR, 32);
fields[6] = new Field("", "TYPE", Types.SMALLINT, 32);
fields[7] = new Field("", "ORDINAL_POSITION", Types.SMALLINT, 5);
fields[8] = new Field("", "COLUMN_NAME", Types.CHAR, 32);
fields[9] = new Field("", "ASC_OR_DESC", Types.CHAR, 1);
if (Util.isJdbc42()) {
fields[10] = new Field("", "CARDINALITY", Types.BIGINT, 20);
fields[11] = new Field("", "PAGES", Types.BIGINT, 20);
} else {
fields[10] = new Field("", "CARDINALITY", Types.INTEGER, 20);
fields[11] = new Field("", "PAGES", Types.INTEGER, 10);
}
fields[12] = new Field("", "FILTER_CONDITION", Types.CHAR, 32);
return fields;
}
示例2: addUser
public int addUser(User user) throws WebQQDaoException{
try{
Object[] args = new Object[]{
user.getId(),
user.getUsername(),
user.getPassword(),
user.getEmail()
};
int[] argTypes = new int[]{
Types.VARCHAR,
Types.VARCHAR,
Types.CHAR,
Types.VARCHAR
};
return jdbcTemplate.update(
SQL_ADD_USER,
args,
argTypes
);
} catch (Exception ex){
throw new WebQQDaoException(SQL_ADD_USER, ex);
}
}
示例3: createProcedureColumnsFields
protected Field[] createProcedureColumnsFields() {
Field[] fields = new Field[20];
fields[0] = new Field("", "PROCEDURE_CAT", Types.CHAR, 512);
fields[1] = new Field("", "PROCEDURE_SCHEM", Types.CHAR, 512);
fields[2] = new Field("", "PROCEDURE_NAME", Types.CHAR, 512);
fields[3] = new Field("", "COLUMN_NAME", Types.CHAR, 512);
fields[4] = new Field("", "COLUMN_TYPE", Types.CHAR, 64);
fields[5] = new Field("", "DATA_TYPE", Types.SMALLINT, 6);
fields[6] = new Field("", "TYPE_NAME", Types.CHAR, 64);
fields[7] = new Field("", "PRECISION", Types.INTEGER, 12);
fields[8] = new Field("", "LENGTH", Types.INTEGER, 12);
fields[9] = new Field("", "SCALE", Types.SMALLINT, 12);
fields[10] = new Field("", "RADIX", Types.SMALLINT, 6);
fields[11] = new Field("", "NULLABLE", Types.SMALLINT, 6);
fields[12] = new Field("", "REMARKS", Types.CHAR, 512);
fields[13] = new Field("", "COLUMN_DEF", Types.CHAR, 512);
fields[14] = new Field("", "SQL_DATA_TYPE", Types.INTEGER, 12);
fields[15] = new Field("", "SQL_DATETIME_SUB", Types.INTEGER, 12);
fields[16] = new Field("", "CHAR_OCTET_LENGTH", Types.INTEGER, 12);
fields[17] = new Field("", "ORDINAL_POSITION", Types.INTEGER, 12);
fields[18] = new Field("", "IS_NULLABLE", Types.CHAR, 512);
fields[19] = new Field("", "SPECIFIC_NAME", Types.CHAR, 512);
return fields;
}
示例4: getSelectClauseNullString
@Override
public String getSelectClauseNullString(int sqlType) {
String literal;
switch ( sqlType ) {
case Types.VARCHAR:
case Types.CHAR:
literal = "'x'";
break;
case Types.DATE:
literal = "'2000-1-1'";
break;
case Types.TIMESTAMP:
literal = "'2000-1-1 00:00:00'";
break;
case Types.TIME:
literal = "'00:00:00'";
break;
default:
literal = "0";
}
return "nullif(" + literal + ',' + literal + ')';
}
示例5: getHibernateType
public Type getHibernateType(int columnPos) throws SQLException {
int columnType = resultSetMetaData.getColumnType( columnPos );
int scale = resultSetMetaData.getScale( columnPos );
int precision = resultSetMetaData.getPrecision( columnPos );
int length = precision;
if ( columnType == Types.CHAR && precision == 0 ) {
length = resultSetMetaData.getColumnDisplaySize( columnPos );
}
return factory.getTypeResolver().heuristicType(
factory.getDialect().getHibernateTypeName(
columnType,
length,
precision,
scale
)
);
}
示例6: buildResultSet
static java.sql.ResultSet buildResultSet(com.mysql.jdbc.Field[] fields, java.util.ArrayList<ResultSetRow> rows, MySQLConnection c) throws SQLException {
int fieldsLength = fields.length;
for (int i = 0; i < fieldsLength; i++) {
int jdbcType = fields[i].getSQLType();
switch (jdbcType) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
fields[i].setEncoding(c.getCharacterSetMetadata(), c);
break;
default:
// do nothing
}
fields[i].setConnection(c);
fields[i].setUseOldNameMetadata(true);
}
return com.mysql.jdbc.ResultSetImpl.getInstance(c.getCatalog(), fields, new RowDataStatic(rows), c, null, false);
}
示例7: convert
public Integer convert(String value) {
if ("ARRAY".equals(value)) { return Types.ARRAY; }
if ("BIGINT".equals(value)) { return Types.BIGINT; }
if ("BINARY".equals(value)) { return Types.BINARY; }
if ("BIT".equals(value)) { return Types.BIT; }
if ("BLOB".equals(value)) { return Types.BLOB; }
if ("BOOLEAN".equals(value)) { return Types.BOOLEAN; }
if ("CHAR".equals(value)) { return Types.CHAR; }
if ("CLOB".equals(value)) { return Types.CLOB; }
return Types.OTHER;
}
示例8: getNativeCharacterStream
/**
* JDBC 2.0
*
* <p>
* Get the value of a column in the current row as a java.io.Reader.
* </p>
*
* @param columnIndex
* the column to get the value from
*
* @return the value in the column as a java.io.Reader.
*
* @throws SQLException
* if an error occurs
*/
protected java.io.Reader getNativeCharacterStream(int columnIndex) throws SQLException {
int columnIndexMinusOne = columnIndex - 1;
switch (this.fields[columnIndexMinusOne].getSQLType()) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.CLOB:
if (this.thisRow.isNull(columnIndexMinusOne)) {
this.wasNullFlag = true;
return null;
}
this.wasNullFlag = false;
return this.thisRow.getReader(columnIndexMinusOne);
}
String asString = getStringForClob(columnIndex);
if (asString == null) {
return null;
}
return getCharacterStreamFromString(asString);
}
示例9: trimDBString
private static Object trimDBString(Object o, int colType) {
Object ret = null;
if (colType == Types.VARCHAR) {
String val = (String) o;
val = StringUtils.trimToEmpty(val);
if (val.length() != 0)
ret = val;
return ret;
} else if (colType == Types.CHAR) {
// Only determine if it should be null
if (StringUtils.trimToEmpty((String)o).length() == 0)
return ret;
}
return o;
}
示例10: 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;
}
示例11: isCaseSensitive
/**
* Does a column's case matter?
*
* @param column
* the first column is 1, the second is 2...
*
* @return true if so
*
* @throws java.sql.SQLException
* if a database access error occurs
*/
public boolean isCaseSensitive(int column) throws java.sql.SQLException {
Field field = getField(column);
int sqlType = field.getSQLType();
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.DATE:
case Types.TIME:
case Types.TIMESTAMP:
return false;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
if (field.isBinary()) {
return true;
}
String collationName = field.getCollation();
return ((collationName != null) && !collationName.endsWith("_ci"));
default:
return true;
}
}
示例12: isStringType
private static boolean isStringType(int type) {
return type == Types.CHAR || type == Types.NCHAR
|| type == Types.VARCHAR || type == Types.LONGVARCHAR
|| type == Types.NVARCHAR;
}
示例13: isJdbcCharacterColumn
public boolean isJdbcCharacterColumn() {
return jdbcType == Types.CHAR || jdbcType == Types.CLOB
|| jdbcType == Types.LONGVARCHAR || jdbcType == Types.VARCHAR
|| jdbcType == Types.LONGNVARCHAR || jdbcType == Types.NCHAR
|| jdbcType == Types.NCLOB || jdbcType == Types.NVARCHAR;
}
示例14: test_mysql
@Test(expectedExceptions = RuntimeException.class)
public void test_mysql() {
DbDataMedia media = getMysqlMedia();
final DbDialect dbDialect = dbDialectFactory.getDbDialect(2L, media.getSource());
want.object(dbDialect).clazIs(MysqlDialect.class);
final SqlTemplate sqlTemplate = dbDialect.getSqlTemplate();
final JdbcTemplate jdbcTemplate = dbDialect.getJdbcTemplate();
final TransactionTemplate transactionTemplate = dbDialect.getTransactionTemplate();
final int[] pkColumnTypes = { Types.INTEGER, Types.VARCHAR };
final int[] columnTypes = { Types.CHAR, Types.DECIMAL, Types.BLOB, Types.CLOB, Types.DATE, Types.TIMESTAMP,
Types.TIMESTAMP };
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
int affect = 0;
String sql = null;
// 执行insert
sql = sqlTemplate.getInsertSql(MYSQL_SCHEMA_NAME, TABLE_NAME, pkColumns, columns);
System.out.println(sql);
affect = (Integer) jdbcTemplate.execute(sql, new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
doPreparedStatement(ps,
dbDialect,
toTypes(columnTypes, pkColumnTypes),
toValues(columnValues, pkColumnValues));
return ps.executeUpdate();
}
});
want.number(affect).isEqualTo(1);
// 执行update
sql = sqlTemplate.getUpdateSql(MYSQL_SCHEMA_NAME, TABLE_NAME, pkColumns, columns);
System.out.println(sql);
affect = (Integer) jdbcTemplate.execute(sql, new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
doPreparedStatement(ps,
dbDialect,
toTypes(columnTypes, pkColumnTypes),
toValues(columnValues, pkColumnValues));
return ps.executeUpdate();
}
});
want.number(affect).isEqualTo(1);
// 执行deleate
sql = sqlTemplate.getDeleteSql(MYSQL_SCHEMA_NAME, TABLE_NAME, pkColumns);
System.out.println(sql);
affect = (Integer) jdbcTemplate.execute(sql, new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
doPreparedStatement(ps, dbDialect, toTypes(pkColumnTypes), toValues(pkColumnValues));
return ps.executeUpdate();
}
});
want.number(affect).isEqualTo(1);
// 执行merge
sql = sqlTemplate.getMergeSql(MYSQL_SCHEMA_NAME, TABLE_NAME, pkColumns, columns, null);
System.out.println(sql);
affect = (Integer) jdbcTemplate.execute(sql, new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
doPreparedStatement(ps,
dbDialect,
toTypes(columnTypes, pkColumnTypes),
toValues(columnValues, pkColumnValues));
return ps.executeUpdate();
}
});
want.number(affect).isEqualTo(1);
throw new RuntimeException("rollback");
}
});
}
示例15: jdbcTypeToClass
/**
* Get the Java type which corresponds to given SQL type.
* @param type SQL type
* @return The Java type
*/
public static Class<?> jdbcTypeToClass(int type) {
Class<?> result = Object.class;
switch (type) {
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
result = String.class;
break;
case Types.NUMERIC:
case Types.DECIMAL:
result = java.math.BigDecimal.class;
break;
case Types.BIT:
result = Boolean.class;
break;
case Types.TINYINT:
result = Byte.class;
break;
case Types.SMALLINT:
result = Short.class;
break;
case Types.INTEGER:
result = Integer.class;
break;
case Types.BIGINT:
result = Long.class;
break;
case Types.REAL:
case Types.FLOAT:
result = Float.class;
break;
case Types.DOUBLE:
result = Double.class;
break;
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
result = byte[].class;
break;
case Types.DATE:
result = java.sql.Date.class;
break;
case Types.TIME:
result = java.sql.Time.class;
break;
case Types.TIMESTAMP:
result = java.sql.Timestamp.class;
break;
default:
break;
}
return result;
}