List of usage examples for java.sql Types OTHER
int OTHER
To view the source code for java.sql Types OTHER.
Click Source Link
getObject
and setObject
. From source file:edumsg.core.commands.user.GetUser2Command.java
@Override public void execute() { try {/*from ww w .jav a2 s .co m*/ details = null; //Cache.returnUser(map.get("username")); User user = new User(); if (details == null) { dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(false); proc = dbConn.prepareCall("{? = call get_user2(?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.OTHER); proc.setString(2, map.get("username")); proc.execute(); set = (ResultSet) proc.getObject(1); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); if (set.next()) { Integer id = set.getInt(1); String username = set.getString(2); String email = set.getString(3); String name = set.getString(5); String language = set.getString(6); String country = set.getString(7); String bio = set.getString(8); String website = set.getString(9); Timestamp created_at = set.getTimestamp(10); String avatar_url = set.getString(11); Boolean overlay = set.getBoolean(12); String link_color = set.getString(13); String background_color = set.getString(14); Boolean protected_tweets = set.getBoolean(15); user.setId(id); user.setUsername(username); user.setEmail(email); user.setName(name); user.setLanguage(language); user.setCountry(country); user.setBio(bio); user.setWebsite(website); user.setCreatedAt(created_at); user.setAvatarUrl(avatar_url); user.setOverlay(overlay); user.setLinkColor(link_color); user.setBackgroundColor(background_color); user.setProtectedTweets(protected_tweets); } set.close(); proc.close(); } else { user.setId(Integer.parseInt(details.get("id"))); user.setUsername(details.get("username")); user.setEmail(details.get("email")); user.setName(details.get("name")); user.setLanguage(details.get("language")); user.setCountry(details.get("country")); user.setBio(details.get("bio")); user.setWebsite(details.get("website")); user.setCreatedAt(Timestamp.valueOf(details.get("created_at"))); user.setAvatarUrl(details.get("avatar_url")); user.setOverlay(Boolean.parseBoolean(details.get("overlay"))); user.setLinkColor(details.get("link_color")); user.setBackgroundColor(details.get("background_color")); user.setProtectedTweets(Boolean.parseBoolean(details.get("protected_tweets"))); } ValueNode child = nf.pojoNode(user); root.set("user", child); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); } catch (JsonGenerationException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (JsonMappingException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } dbConn.commit(); } catch (PSQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(set, proc, dbConn, null); } }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the SQL type name for the given {@link Types} constant. *//* w w w . j a v a2s. c o m*/ public static String getJDBCName(int type) { switch (type) { case Types.ARRAY: return "array"; case Types.BIGINT: return "bigint"; case Types.BINARY: return "binary"; case Types.BIT: return "bit"; case Types.BLOB: return "blob"; case Types.CHAR: return "char"; case Types.CLOB: return "clob"; case Types.DATE: return "date"; case Types.DECIMAL: return "decimal"; case Types.DISTINCT: return "distinct"; case Types.DOUBLE: return "double"; case Types.FLOAT: return "float"; case Types.INTEGER: return "integer"; case Types.JAVA_OBJECT: return "java_object"; case Types.LONGVARBINARY: return "longvarbinary"; case Types.LONGVARCHAR: return "longvarchar"; case Types.NULL: return "null"; case Types.NUMERIC: return "numeric"; case Types.OTHER: return "other"; case Types.REAL: return "real"; case Types.REF: return "ref"; case Types.SMALLINT: return "smallint"; case Types.STRUCT: return "struct"; case Types.TIME: return "time"; case Types.TIMESTAMP: return "timestamp"; case Types.TINYINT: return "tinyint"; case Types.VARBINARY: return "varbinary"; case Types.VARCHAR: return "varchar"; default: return "unknown(" + type + ")"; } }
From source file:RowSetModel.java
public Class getColumnClass(int column) { String cname;//from w ww .ja v a 2 s . c o m int type; try { ResultSetMetaData meta = rowSet.getMetaData(); if (meta == null) { return null; } type = meta.getColumnType(column + 1); } catch (SQLException e) { e.printStackTrace(); return super.getColumnClass(column); } switch (type) { case Types.BIT: { cname = "java.lang.Boolean"; break; } case Types.TINYINT: { cname = "java.lang.Byte"; break; } case Types.SMALLINT: { cname = "java.lang.Short"; break; } case Types.INTEGER: { cname = "java.lang.Integer"; break; } case Types.BIGINT: { cname = "java.lang.Long"; break; } case Types.FLOAT: case Types.REAL: { cname = "java.lang.Float"; break; } case Types.DOUBLE: { cname = "java.lang.Double"; break; } case Types.NUMERIC: { cname = "java.lang.Number"; break; } case Types.DECIMAL: { cname = "java.math.BigDecimal"; break; } case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { cname = "java.lang.String"; break; } case Types.DATE: { cname = "java.sql.Date"; break; } case Types.TIME: { cname = "java.sql.Time"; break; } case Types.TIMESTAMP: { cname = "java.sql.Timestamp"; break; } case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: { cname = "byte[]"; break; } case Types.OTHER: case Types.JAVA_OBJECT: { cname = "java.lang.Object"; break; } case Types.CLOB: { cname = "java.sql.Clob"; break; } case Types.BLOB: { cname = "java.ssql.Blob"; break; } case Types.REF: { cname = "java.sql.Ref"; break; } case Types.STRUCT: { cname = "java.sql.Struct"; break; } default: { return super.getColumnClass(column); } } try { return Class.forName(cname); } catch (Exception e) { e.printStackTrace(); return super.getColumnClass(column); } }
From source file:ro.nextreports.engine.querybuilder.sql.dialect.AbstractDialect.java
/** * Get <tt>java.sql.Types</tt> typecode of the column database associated * with the given sql type, precision and scale. * // www . j ava 2s .c om * @param type sql type * @param precision the precision of the column * @param scale the scale of the column * * @return the column typecode * @throws DialectException */ public final int getJdbcType(String type, int precision, int scale) throws DialectException { // TODO ?! // SQLite returns "null" for type if we use rsmd.getColumnTypeName if ((type == null) || "null".equals(type)) { return Types.OTHER; } List<ColumnTypeMatcher> typeMatchers = matchType(type, columnTypeMatchers); if (typeMatchers.size() == 0) { throw new DialectException("Cannot match the type '" + type + "' to a jdbc type"); } if (typeMatchers.size() == 1) { return jdbcTypes.get(typeMatchers.get(0).getColumnType()); } List<ColumnTypeMatcher> precisionMatchers = matchPrecision(precision, typeMatchers); if (precisionMatchers.size() == 0) { throw new DialectException("Cannot match the precision '" + precision + "' to a jdbc type"); } if (precisionMatchers.size() == 1) { return jdbcTypes.get(precisionMatchers.get(0).getColumnType()); } List<ColumnTypeMatcher> scaleMatchers = matchScale(scale, typeMatchers); if (scaleMatchers.size() == 0) { throw new DialectException("Cannot match the scale '" + scale + "' to a jdbc type"); } if (scaleMatchers.size() == 1) { return jdbcTypes.get(scaleMatchers.get(0).getColumnType()); } return jdbcTypes.get(chooseOne(scaleMatchers).getColumnType()); }
From source file:net.sourceforge.squirrel_sql.plugins.postgres.types.PostgreSqlGeometryTypeDataTypeComponentFactory.java
@Override public boolean matches(DialectType dialectType, int sqlType, String sqlTypeName) { return new EqualsBuilder().append(getDialectType(), dialectType).append(Types.OTHER, sqlType) .append("geometry", sqlTypeName).isEquals(); }
From source file:org.apache.ojb.broker.metadata.FieldTypeClasses.java
/** * Returns a {@link FieldType} instance for the given sql type * (see {@link java.sql.Types}) as specified in JDBC 3.0 specification * (see JDBC 3.0 specification <em>Appendix B, Data Type Conversion Tables</em>). * * @param jdbcType Specify the type to look for. * @return A new specific {@link FieldType} instance. */// w w w .j ava 2 s . c o m static FieldType newFieldType(JdbcType jdbcType) { FieldType result = null; switch (jdbcType.getType()) { case Types.ARRAY: result = new ArrayFieldType(); break; case Types.BIGINT: result = new LongFieldType(); break; case Types.BINARY: result = new ByteArrayFieldType(); break; case Types.BIT: result = new BooleanFieldType(); break; case Types.BLOB: result = new BlobFieldType(); break; case Types.CHAR: result = new StringFieldType(); break; case Types.CLOB: result = new ClobFieldType(); break; case Types.DATE: result = new DateFieldType(); break; case Types.DECIMAL: result = new BigDecimalFieldType(); break; // Not needed, user have to use the underlying sql datatype in OJB mapping files // case Types.DISTINCT: // result = new DistinctFieldType(); // break; case Types.DOUBLE: result = new DoubleFieldType(); break; case Types.FLOAT: result = new FloatFieldType(); break; case Types.INTEGER: result = new IntegerFieldType(); break; case Types.JAVA_OBJECT: result = new JavaObjectFieldType(); break; case Types.LONGVARBINARY: result = new ByteArrayFieldType(); break; case Types.LONGVARCHAR: result = new StringFieldType(); break; case Types.NUMERIC: result = new BigDecimalFieldType(); break; case Types.REAL: result = new FloatFieldType(); break; case Types.REF: result = new RefFieldType(); break; case Types.SMALLINT: result = new ShortFieldType(); break; case Types.STRUCT: result = new StructFieldType(); break; case Types.TIME: result = new TimeFieldType(); break; case Types.TIMESTAMP: result = new TimestampFieldType(); break; case Types.TINYINT: result = new ByteFieldType(); break; case Types.VARBINARY: result = new ByteArrayFieldType(); break; case Types.VARCHAR: result = new StringFieldType(); break; case Types.OTHER: result = new JavaObjectFieldType(); break; // // case Types.NULL: // result = new NullFieldType(); // break; //#ifdef JDBC30 case Types.BOOLEAN: result = new BooleanFieldType(); break; case Types.DATALINK: result = new URLFieldType(); break; //#endif default: throw new OJBRuntimeException("Unkown or not supported field type specified, specified jdbc type was '" + jdbcType + "', as string: " + JdbcTypesHelper.getSqlTypeAsString(jdbcType.getType())); } // make sure that the sql type was set result.setSqlType(jdbcType); return result; }
From source file:org.metis.jdbc.WdsStoredProcedure.java
public WdsStoredProcedure(SqlStmnt stmt) throws Exception { super(stmt.getJdbcTemplate(), stmt.getStoredProcName()); setFunction(stmt.isFunction());/* w ww .j av a 2s. c om*/ myStmt = stmt; // Parameters should be declared in the same order that // they are declared in the stored procedure. The one exception // are result sets, which must be defined first!! // // Here's something I found as to why - When you make any private // static class of StoreProcedure, then in its constructor you must // declare SqlReturnResultSet before you declare SqlParameter. // Otherwise you will not be able to find return data from // StoredProcedure execution. Still not sure what this means // and why its so. // for (SqlToken sqlToken : myStmt.getSortedKeyTokens()) { if (sqlToken.isRset()) { declareParameter(new SqlReturnResultSet(sqlToken.getKey(), myStmt)); } } // now do the other parameters // iterate through tokens in proper sequence; parameters must be // declared according to the sequence in which they appear in the // statement for (SqlToken sqlToken : myStmt.getSortedKeyTokens()) { // skip result sets if (sqlToken.isRset()) { continue; } switch (sqlToken.getMode()) { case IN: declareParameter(new SqlParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType())); break; case OUT: // look for CURSOR types if (sqlToken.isCursor()) { // if it is a cursor then check to see if it is Oracle or // some other DBMS and set the type accrodingly int type = (myStmt.getMetisController().isOracle()) ? ORACLE_CURSOR : Types.OTHER; declareParameter(new SqlOutParameter(sqlToken.getKey(), type, myStmt)); } else { declareParameter(new SqlOutParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType())); } break; case INOUT: // note: you can't have cursors as IN params - doesn't // make sense, so don't check for them when its an INOUT declareParameter(new SqlInOutParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType())); break; default: throw new Exception("WdsStoredProcedure: this invalid mode was provided: " + sqlToken.getMode()); } } // specify whether this is a function super.setFunction(myStmt.isFunction()); // compile the statement compile(); }
From source file:edumsg.core.commands.user.LoginCommand.java
@Override public void execute() { try {// w ww. j a v a 2 s . co m String sessionID = URLEncoder.encode(new UID().toString(), "UTF-8"); String cleaned_session = sessionID.replace("%", "\\%"); dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(false); proc = dbConn.prepareCall("{? = call get_password_info(?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.VARCHAR); proc.setString(2, map.get("username")); proc.execute(); String enc_password = proc.getString(1); if (enc_password == null) { CommandsHelp.handleError(map.get("app"), map.get("method"), "Invalid username", map.get("correlation_id"), LOGGER); return; } proc.close(); dbConn.commit(); boolean authenticated = BCrypt.checkpw(map.get("password"), enc_password); if (authenticated) { User user = new User(); Statement query = dbConn.createStatement(); // query = dbConn.createStatement(); // query.setPoolable(true); // set = query.executeQuery(String.format("SELECT * FROM login('%s','%s')" // , map.get("username") // , cleaned_session)); proc = dbConn.prepareCall("{? = call login(?,?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.OTHER); proc.setString(2, map.get("username")); proc.setString(3, cleaned_session); proc.execute(); set = (ResultSet) proc.getObject(1); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); while (set.next()) { id = set.getInt("id"); username = set.getString("username"); email = set.getString("email"); name = set.getString("name"); language = set.getString("language"); country = set.getString("country"); bio = set.getString("bio"); website = set.getString("website"); created_at = set.getTimestamp("created_at"); avatar_url = set.getString("avatar_url"); overlay = set.getBoolean("overlay"); link_color = set.getString("link_color"); background_color = set.getString("background_color"); protected_tweets = set.getBoolean("protected_tweets"); user.setUsername(username); user.setEmail(email); user.setName(name); user.setLanguage(language); user.setCountry(country); user.setBio(bio); user.setWebsite(website); user.setCreatedAt(created_at); user.setAvatarUrl(avatar_url); user.setOverlay(overlay); user.setLinkColor(link_color); user.setBackgroundColor(background_color); user.setProtectedTweets(protected_tweets); user.setSessionID(sessionID); details = new HashMap<String, String>(); details.put("id", id.toString()); details.put("username", username); details.put("email", email); details.put("name", name); details.put("language", language); details.put("country", country); details.put("bio", bio); details.put("website", website); details.put("created_at", created_at.toString()); details.put("avatar_url", avatar_url); details.put("overlay", overlay.toString()); details.put("link_color", link_color); details.put("background_color", background_color); details.put("protected_tweets", protected_tweets.toString()); details.put("session_id", sessionID); } proc.close(); dbConn.commit(); user.setSessionID(cleaned_session); UserCache.cacheUser(id.toString(), details); UserCache.mapUsernameID(username, id + ""); UserCache.cacheUserSession(cleaned_session, details.get("id")); ValueNode child = nf.pojoNode(user); root.set("user", child); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); } catch (Exception e) { e.printStackTrace(); } } else { CommandsHelp.handleError(map.get("app"), map.get("method"), "Invalid Password", map.get("correlation_id"), LOGGER); } } catch (PSQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (UnsupportedEncodingException e) { //Logger.log(Level.SEVERE, e.getMessage(), e); } catch (Exception e) { e.printStackTrace(); //Logger.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(set, proc, dbConn, null); } }
From source file:org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.java
/** * Creates a new platform instance.// w w w . j a v a 2 s.c o m */ public PostgreSqlPlatform() { PlatformInfo info = getPlatformInfo(); info.setPrimaryKeyColumnAutomaticallyRequired(true); // this is the default length though it might be changed when building PostgreSQL // in file src/include/postgres_ext.h info.setMaxIdentifierLength(31); info.addNativeTypeMapping(Types.ARRAY, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BINARY, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BIT, "BOOLEAN"); info.addNativeTypeMapping(Types.BLOB, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BOOLEAN, "BOOLEAN", Types.BIT); info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.DATALINK, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DECIMAL, "NUMERIC", Types.NUMERIC); info.addNativeTypeMapping(Types.DISTINCT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION"); info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE); info.addNativeTypeMapping(Types.JAVA_OBJECT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.LONGVARBINARY, "BYTEA"); info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT", Types.LONGVARCHAR); info.addNativeTypeMapping(Types.NULL, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.OTHER, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.REF, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.STRUCT, "BYTEA", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT); info.addNativeTypeMapping(Types.VARBINARY, "BYTEA", Types.LONGVARBINARY); info.setDefaultSize(Types.CHAR, 254); info.setDefaultSize(Types.VARCHAR, 254); // no support for specifying the size for these types (because they are mapped // to BYTEA which back-maps to BLOB) info.setHasSize(Types.BINARY, false); info.setHasSize(Types.VARBINARY, false); setSqlBuilder(new PostgreSqlBuilder(this)); setModelReader(new PostgreSqlModelReader(this)); }
From source file:org.apache.openjpa.jdbc.schema.Schemas.java
/** * Return the {@link Types} constant for the given SQL type name. *//* w w w .j ava 2 s . com*/ public static int getJDBCType(String name) { if ("array".equalsIgnoreCase(name)) return Types.ARRAY; if ("bigint".equalsIgnoreCase(name)) return Types.BIGINT; if ("binary".equalsIgnoreCase(name)) return Types.BINARY; if ("bit".equalsIgnoreCase(name)) return Types.BIT; if ("blob".equalsIgnoreCase(name)) return Types.BLOB; if ("char".equalsIgnoreCase(name)) return Types.CHAR; if ("clob".equalsIgnoreCase(name)) return Types.CLOB; if ("date".equalsIgnoreCase(name)) return Types.DATE; if ("decimal".equalsIgnoreCase(name)) return Types.DECIMAL; if ("distinct".equalsIgnoreCase(name)) return Types.DISTINCT; if ("double".equalsIgnoreCase(name)) return Types.DOUBLE; if ("float".equalsIgnoreCase(name)) return Types.FLOAT; if ("integer".equalsIgnoreCase(name)) return Types.INTEGER; if ("java_object".equalsIgnoreCase(name)) return Types.JAVA_OBJECT; if ("longvarbinary".equalsIgnoreCase(name)) return Types.LONGVARBINARY; if ("longvarchar".equalsIgnoreCase(name)) return Types.LONGVARCHAR; if ("null".equalsIgnoreCase(name)) return Types.NULL; if ("numeric".equalsIgnoreCase(name)) return Types.NUMERIC; if ("other".equalsIgnoreCase(name)) return Types.OTHER; if ("real".equalsIgnoreCase(name)) return Types.REAL; if ("ref".equalsIgnoreCase(name)) return Types.REF; if ("smallint".equalsIgnoreCase(name)) return Types.SMALLINT; if ("struct".equalsIgnoreCase(name)) return Types.STRUCT; if ("time".equalsIgnoreCase(name)) return Types.TIME; if ("timestamp".equalsIgnoreCase(name)) return Types.TIMESTAMP; if ("tinyint".equalsIgnoreCase(name)) return Types.TINYINT; if ("varbinary".equalsIgnoreCase(name)) return Types.VARBINARY; if ("varchar".equalsIgnoreCase(name)) return Types.VARCHAR; if (name == null || name.toLowerCase().startsWith("unknown")) return Types.OTHER; throw new IllegalArgumentException("name = " + name); }