Example usage for java.sql Types OTHER

List of usage examples for java.sql Types OTHER

Introduction

In this page you can find the example usage for java.sql Types OTHER.

Prototype

int OTHER

To view the source code for java.sql Types OTHER.

Click Source Link

Document

The constant in the Java programming language that indicates that the SQL type is database-specific and gets mapped to a Java object that can be accessed via the methods getObject and setObject.

Usage

From source file:com.servoy.j2db.util.Utils.java

/**
 * Parse a javascript string into a java string, example parseJSString("'HelloWorld'") returns:HelloWorld
 * @param o// w w w  . j  a  va2s .  co  m
 *
 * @return the parsed object
 */
public static Object parseJSExpression(Object o) {
    return parseJSExpression(o, Types.OTHER);
}

From source file:org.pentaho.di.jdbc.Support.java

/**
 * Get a String describing the supplied JDBC type constant.
 *
 * @param jdbcType The constant to be decoded.
 * @return The text decode of the type constant as a <code>String</code>.
 *//*from   w  ww . j  a  v a  2  s  . c o  m*/
static String getJdbcTypeName(int jdbcType) {
    switch (jdbcType) {
    case java.sql.Types.ARRAY:
        return "ARRAY";
    case java.sql.Types.BIGINT:
        return "BIGINT";
    case java.sql.Types.BINARY:
        return "BINARY";
    case java.sql.Types.BIT:
        return "BIT";
    case java.sql.Types.BLOB:
        return "BLOB";
    case java.sql.Types.BOOLEAN:
        return "BOOLEAN";
    case java.sql.Types.CHAR:
        return "CHAR";
    case java.sql.Types.CLOB:
        return "CLOB";
    //            case JtdsStatement.DATALINK:       return "DATALINK";
    case java.sql.Types.DATE:
        return "DATE";
    case java.sql.Types.DECIMAL:
        return "DECIMAL";
    case java.sql.Types.DISTINCT:
        return "DISTINCT";
    case java.sql.Types.DOUBLE:
        return "DOUBLE";
    case java.sql.Types.FLOAT:
        return "FLOAT";
    case java.sql.Types.INTEGER:
        return "INTEGER";
    case java.sql.Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case java.sql.Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case java.sql.Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case java.sql.Types.NULL:
        return "NULL";
    case java.sql.Types.NUMERIC:
        return "NUMERIC";
    case java.sql.Types.OTHER:
        return "OTHER";
    case java.sql.Types.REAL:
        return "REAL";
    case java.sql.Types.REF:
        return "REF";
    case java.sql.Types.SMALLINT:
        return "SMALLINT";
    case java.sql.Types.STRUCT:
        return "STRUCT";
    case java.sql.Types.TIME:
        return "TIME";
    case java.sql.Types.TIMESTAMP:
        return "TIMESTAMP";
    case java.sql.Types.TINYINT:
        return "TINYINT";
    case java.sql.Types.VARBINARY:
        return "VARBINARY";
    case java.sql.Types.VARCHAR:
        return "VARCHAR";
    default:
        return "ERROR";
    }
}

From source file:com.servoy.j2db.util.Utils.java

/**
 *   The same as parseJSExpression but try to convert the object to the given type parameter
 * @param  type from java.sql.Types  ,  java.sql.Types.OTHER to get the behavior of parseJSExpression(Object o)
 *///from   w w w .j  av a 2s .  c  om
public static Object parseJSExpression(Object o, int type) {
    if (o instanceof String) {
        int tp = Column.mapToDefaultType(type);

        String s = ((String) o).trim();
        if ("".equals(s))
            return null;
        if (tp == Types.OTHER || type == Types.BOOLEAN || type == Types.BIT) {
            if ("true".equals(s))
                return Boolean.TRUE;
            if ("false".equals(s))
                return Boolean.FALSE;
            if (type == Types.BOOLEAN || type == Types.BIT)
                return null;
        }
        if (tp == Types.OTHER || tp == IColumnTypes.NUMBER) {
            try {
                return Double.valueOf(s);
            } catch (NumberFormatException e) {
                if (tp != Types.OTHER)
                    return null;
            }
        }

        if (tp == IColumnTypes.INTEGER) {
            try {
                return Integer.valueOf(s);
            } catch (NumberFormatException e) {
                if ("true".equals(s))
                    return Boolean.TRUE;
                if ("false".equals(s))
                    return Boolean.FALSE;
                return null;
            }
        }

        if (tp == Types.OTHER || tp == IColumnTypes.TEXT) {
            if ((s.charAt(0) == '\'' && s.charAt(s.length() - 1) == '\'')
                    || (s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"')) {
                return s.substring(1, s.length() - 1);
            }
        }

        return null;
    }

    // non-string, keep original
    return o;
}

From source file:org.siphon.jssql.SqlExecutor.java

private String translateTypeName(int columnType, String columnTypeName) {
    switch (columnType) {
    case Types.VARCHAR:
    case Types.CHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
        return "STRING";

    case Types.INTEGER:
    case Types.SMALLINT:
        return "INT";
    case Types.BIGINT:
        return "LONG";
    case Types.FLOAT:
        return "FLOAT";
    case Types.REAL:
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.NUMERIC:
    case Types.DECIMAL:
        return "DECIMAL";

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.TIME_WITH_TIMEZONE:
        return "DATE";

    case Types.ROWID:
        return "ROWID";

    case Types.BLOB:
        return "BINARY"; // return "BLOB";

    case Types.CLOB:
        return "STRING"; // return "CLOB";

    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return "BINARY";

    case Types.BOOLEAN:
        return "BOOLEAN";

    case Types.ARRAY:
        return "ARRAY";

    case Types.OTHER:
        return columnTypeName.toUpperCase();

    default://from   w ww .j ava2  s.  c o m
        return "UNKNOWN";
    }
}

From source file:org.seasar.dbflute.logic.replaceschema.loaddata.impl.DfAbsractDataWriter.java

protected boolean processArray(String tableName, String columnName, String value, PreparedStatement ps,
        int bindCount, Map<String, DfColumnMeta> columnInfoMap) throws SQLException {
    if (value == null) {
        return false; // basically no way
    }/*from   w  w  w . j av  a 2  s  .  co  m*/
    final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
    if (columnInfo != null) {
        if (getBasicProperties().isDatabasePostgreSQL()) {
            //rsMeta#getColumnTypeName() returns value starts with "_" if
            //rsMeta#getColumnType() returns Types.ARRAY in PostgreSQL.
            //  e.g. UUID[] -> _uuid
            final int jdbcDefValue = columnInfo.getJdbcDefValue();
            final String dbTypeName = columnInfo.getDbTypeName();
            if (jdbcDefValue != Types.ARRAY || !dbTypeName.startsWith("_")) {
                return false;
            }
            value = filterArrayValue(value);
            ps.setObject(bindCount, value, Types.OTHER);
            return true;
        }
    }
    // unsupported when meta data is not found
    return false;
}

From source file:com.squid.kraken.v4.caching.redis.datastruct.RawMatrix.java

public static String getJavaDatatype(int colType) {

    switch (colType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return "java.lang.String";

    case Types.NUMERIC:
    case Types.DECIMAL:
        return "java.math.BigDecimal";

    case Types.BIT:
        return "boolean";

    case Types.TINYINT:
        return "byte";

    case Types.SMALLINT:
        return "short";

    case Types.INTEGER:
        return "int";

    case Types.BIGINT:
        return "long";

    case Types.REAL:
        return "float";

    case Types.FLOAT:
    case Types.DOUBLE:
        return "double";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return "byte[]";

    case Types.DATE:
        return "java.sql.Date";

    case Types.TIME:
        return "java.sql.Time";

    case Types.TIMESTAMP:
        return "java.sql.Timestamp";

    case Types.OTHER:
        return "java.lang.Object";
    default:/*ww  w . j a v a  2  s  .  c o m*/
        return null;
    }
}

From source file:org.jumpmind.symmetric.db.ase.AseTriggerTemplate.java

@Override
protected String buildKeyVariablesDeclare(Column[] columns, String prefix) {
    String text = "";
    for (int i = 0; i < columns.length; i++) {
        text += "declare @" + prefix + "pk" + i + " ";
        switch (columns[i].getMappedTypeCode()) {
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
            // ASE does not support bigint
            text += "NUMERIC(18,0)\n";
            break;
        case Types.NUMERIC:
        case Types.DECIMAL:
            // Use same default scale and precision used by Sybase ASA
            // for a decimal with unspecified scale and precision.
            text += "decimal(30,6)\n";
            break;
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
            text += "float\n";
            break;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            text += "varchar(1000)\n";
            break;
        case Types.DATE:
            text += "date\n";
            break;
        case Types.TIME:
            text += "time\n";
            break;
        case Types.TIMESTAMP:
            text += "datetime\n";
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            text += "bit\n";
            break;
        case Types.CLOB:
            text += "varchar(32767)\n";
            break;
        case Types.BLOB:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case -10: // SQL-Server ntext binary type
            text += "varbinary(32767)\n";
            break;
        case Types.OTHER:
            text += "varbinary(32767)\n";
            break;
        default://  ww w  . ja  v a2 s .  c  om
            if (columns[i].getJdbcTypeName() != null
                    && columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) {
                text += "interval";
                break;
            }
            throw new NotImplementedException(columns[i] + " is of type " + columns[i].getMappedType());
        }
    }

    return text;
}

From source file:org.seasar.dbflute.logic.replaceschema.loaddata.impl.DfAbsractDataWriter.java

protected boolean processXml(String tableName, String columnName, String value, PreparedStatement ps,
        int bindCount, Map<String, DfColumnMeta> columnInfoMap) throws SQLException {
    if (value == null) {
        return false; // basically no way
    }//  w  w  w.j av a2 s. c om
    final DfColumnMeta columnInfo = columnInfoMap.get(columnName);
    if (columnInfo != null) {
        if (getBasicProperties().isDatabasePostgreSQL()) {
            final String dbTypeName = columnInfo.getDbTypeName();
            if (!dbTypeName.startsWith("xml")) {
                return false;
            }
            value = filterXmlValue(value);
            ps.setObject(bindCount, value, Types.OTHER);
            return true;
        }
    }
    // unsupported when meta data is not found
    return false;
}

From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java

public void testObject() throws SQLException {
    Statement stat = conn.createStatement();
    ResultSet rs;/*from ww  w.  j  av a  2  s.c  o  m*/
    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
    stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
    PreparedStatement prep = conn
            .prepareStatement("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM TEST");
    prep.setObject(1, Boolean.TRUE);
    prep.setObject(2, "Abc");
    prep.setObject(3, new BigDecimal("10.2"));
    prep.setObject(4, new Byte((byte) 0xff));
    prep.setObject(5, new Short(Short.MAX_VALUE));
    prep.setObject(6, new Integer(Integer.MIN_VALUE));
    prep.setObject(7, new Long(Long.MAX_VALUE));
    prep.setObject(8, new Float(Float.MAX_VALUE));
    prep.setObject(9, new Double(Double.MAX_VALUE));
    prep.setObject(10, Date.valueOf("2001-02-03"));
    prep.setObject(11, Time.valueOf("04:05:06"));
    prep.setObject(12, Timestamp.valueOf("2001-02-03 04:05:06.123456789"));
    prep.setObject(13, new java.util.Date(Date.valueOf("2001-02-03").getTime()));
    prep.setObject(14, new byte[] { 10, 20, 30 });
    prep.setObject(15, new Character('a'), Types.OTHER);
    prep.setObject(16, "2001-01-02", Types.DATE);
    // converting to null seems strange...
    prep.setObject(17, "2001-01-02", Types.NULL);
    prep.setObject(18, "3.725", Types.DOUBLE);
    prep.setObject(19, "23:22:21", Types.TIME);
    prep.setObject(20, new java.math.BigInteger("12345"), Types.OTHER);
    rs = prep.executeQuery();
    rs.next();
    assertTrue(rs.getObject(1).equals(Boolean.TRUE));
    assertTrue(rs.getObject(2).equals("Abc"));
    assertTrue(rs.getObject(3).equals(new BigDecimal("10.2")));
    assertTrue(rs.getObject(4).equals((byte) 0xff));
    assertTrue(rs.getObject(5).equals(new Short(Short.MAX_VALUE)));
    assertTrue(rs.getObject(6).equals(new Integer(Integer.MIN_VALUE)));
    assertTrue(rs.getObject(7).equals(new Long(Long.MAX_VALUE)));
    assertTrue(rs.getObject(8).equals(new Float(Float.MAX_VALUE)));
    assertTrue(rs.getObject(9).equals(new Double(Double.MAX_VALUE)));
    assertTrue(rs.getObject(10).equals(Date.valueOf("2001-02-03")));
    assertEquals("04:05:06", rs.getObject(11).toString());
    assertTrue(rs.getObject(11).equals(Time.valueOf("04:05:06")));
    assertTrue(rs.getObject(12).equals(Timestamp.valueOf("2001-02-03 04:05:06.123456789")));
    assertTrue(rs.getObject(13).equals(Timestamp.valueOf("2001-02-03 00:00:00")));
    assertEquals(new byte[] { 10, 20, 30 }, (byte[]) rs.getObject(14));
    assertTrue(rs.getObject(15).equals('a'));
    assertTrue(rs.getObject(16).equals(Date.valueOf("2001-01-02")));
    assertTrue(rs.getObject(17) == null && rs.wasNull());
    assertTrue(rs.getObject(18).equals(new Double(3.725)));
    assertTrue(rs.getObject(19).equals(Time.valueOf("23:22:21")));
    assertTrue(rs.getObject(20).equals(new java.math.BigInteger("12345")));

    // } else if(x instanceof java.io.Reader) {
    // return session.createLob(Value.CLOB,
    // TypeConverter.getInputStream((java.io.Reader)x), 0);
    // } else if(x instanceof java.io.InputStream) {
    // return session.createLob(Value.BLOB, (java.io.InputStream)x, 0);
    // } else {
    // return ValueBytes.get(TypeConverter.serialize(x));

    stat.execute("DROP TABLE TEST");

}

From source file:org.executequery.databasemediators.spi.DefaultStatementExecutor.java

/** <p>Executes the specified procedure and returns
 *  a <code>ResultSet</code> object from this query.
 *  <p>If an exception occurs, null is returned and
 *  the relevant error message, if available, assigned
 *  to this object for retrieval./*from w w  w  . jav a 2s .c  o  m*/
 *
 *  @param  the SQL procedure to execute
 *  @return the query result
 */
private SqlStatementResult executeProcedure(String query) throws SQLException {

    if (!prepared()) {

        return statementResult;
    }

    //Log.debug("query " + query);

    String execString = "EXECUTE ";
    String callString = "CALL ";

    int nameIndex = -1;
    int index = query.toUpperCase().indexOf(execString);

    // check if EXECUTE was entered
    if (index != -1) {

        nameIndex = execString.length();

    } else { // must be CALL

        nameIndex = callString.length();
    }

    String procedureName = null;

    // check for input brackets
    boolean possibleParams = false;
    index = query.indexOf("(", nameIndex);
    if (index != -1) {

        possibleParams = true;
        procedureName = query.substring(nameIndex, index);

    } else {

        procedureName = query.substring(nameIndex);
    }

    String prefix = prefixFromName(procedureName);
    procedureName = suffixFromName(procedureName);

    DatabaseHost host = new DatabaseObjectFactoryImpl().createDatabaseHost(databaseConnection);

    if (prefix == null) {

        prefix = host.getDefaultNamePrefix();
    }

    DatabaseExecutable procedure = host.getDatabaseSource(prefix).getProcedure(procedureName);
    if (procedure == null) { // hedge

        procedure = host.getDatabaseSource(prefix).getFunction(procedureName);
    }

    if (procedure != null) {

        if (possibleParams) {

            String params = query.substring(index + 1, query.indexOf(")"));

            if (!MiscUtils.isNull(params)) {

                // check that the proc accepts params
                //                    if (!procedure.hasParameters()) {
                //                    
                //                        statementResult.setSqlException(new SQLException("Procedure call was invalid"));
                //                        return statementResult;
                //                    }

                int paramIndex = 0;
                ProcedureParameter[] parameters = procedure.getParametersArray();

                // extract the parameters
                StringTokenizer st = new StringTokenizer(params, ",");

                // no defined params from the meta data but params supplied ??
                // attempt to execute as supplied and bubble up db error if an issue
                if (parameters.length == 0) {

                    parameters = new ProcedureParameter[st.countTokens()];
                    for (int i = 0, n = st.countTokens(); i < n; i++) {

                        procedure.addParameter("UNKNOWN", DatabaseMetaData.procedureColumnIn, Types.OTHER,
                                "OTHER", -1);
                    }

                    parameters = procedure.getParametersArray();
                }

                while (st.hasMoreTokens()) {

                    String value = st.nextToken().trim();

                    // check applicable param
                    for (int i = paramIndex; i < parameters.length; i++) {
                        paramIndex++;

                        int type = parameters[i].getType();
                        if (type == DatabaseMetaData.procedureColumnIn
                                || type == DatabaseMetaData.procedureColumnInOut) {

                            // check the data type and remove quotes if char
                            int dataType = parameters[i].getDataType();
                            if (dataType == Types.CHAR || dataType == Types.VARCHAR
                                    || dataType == Types.LONGVARCHAR) {

                                if (value.indexOf("'") != -1) {
                                    // assuming quotes at start and end
                                    value = value.substring(1, value.length() - 1);
                                }

                            }

                            parameters[i].setValue(value);
                            break;
                        }
                    }

                }

            }
        }

        // execute the procedure
        return execute(procedure);

    } else {

        // just run it...

        CallableStatement cstmnt = null;
        try {

            cstmnt = conn.prepareCall(query);
            boolean hasResultSet = cstmnt.execute();

            if (!hasResultSet) {

                statementResult.setUpdateCount(cstmnt.getUpdateCount());

            } else {

                statementResult.setResultSet(cstmnt.getResultSet());
            }

        } catch (SQLException e) {

            handleException(e);
            statementResult.setSqlException(e);
        }

        return statementResult;
        /*
                
        statementResult.setSqlException(
            new SQLException("Procedure or Function name specified is invalid"));
                
        return statementResult;
                
        */
    }

}