Java Code Examples for java.sql.ResultSet#getURL()

The following examples show how to use java.sql.ResultSet#getURL() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultSetWriter.java    From aceql-http with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
    * Format - if detected - an URL
    *
    * @param resultSet
    * @param columnIndex
    * @param columnValueStr
    * @return
    */
   public String urlFormater(ResultSet resultSet, int columnIndex, String columnValueStr) {

try {
    URL url = resultSet.getURL(columnIndex);
    if (url != null) {
	// Its an URL!
	// UrlTransporter urlTransporter = new UrlTransporter();
	// columnValueStr = urlTransporter.toBase64(url);
	columnValueStr = url.toString();
    }

} catch (Exception e) {
    // Do nothing. It's not an URL
}

return columnValueStr;
   }
 
Example 2
Source File: ResultSetGetterAdapterTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void assertGetURLForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets.values()) {
        try {
            each.getURL(1);

            fail("Expected an SQLException to be thrown");
        } catch (final SQLException exception) {
            assertFalse(exception.getMessage().isEmpty());
        }
    }
}
 
Example 3
Source File: ResultSetGetterAdapterTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void assertGetURLForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets.values()) {
        try {
            each.getURL(columnName);
            fail("Expected an SQLException to be thrown");
        } catch (final SQLException exception) {
            assertFalse(exception.getMessage().isEmpty());
        }
    }
}
 
Example 4
Source File: ResultSetGetterAdapterTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Test
public void assertGetURLForColumnIndex() throws SQLException {
    for (ResultSet each : resultSets.values()) {
        try {
            each.getURL(1);
            fail("Expected an SQLException to be thrown");
            // TODO need investigate why throw ClassCastException
        } catch (final ClassCastException ex) {
            assertFalse(ex.getMessage().isEmpty());
        }
    }
}
 
Example 5
Source File: ResultSetGetterAdapterTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Test
public void assertGetURLForColumnLabel() throws SQLException {
    for (ResultSet each : resultSets.values()) {
        try {
            each.getURL(columnName);
            fail("Expected an SQLException to be thrown");
            // TODO need investigate why throw ClassCastException
        } catch (final ClassCastException ex) {
            assertFalse(ex.getMessage().isEmpty());
        }
    }
}
 
Example 6
Source File: Jdbc41Bridge.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Delegates to {@link ResultSet#getObject(int, Class)} without throwing a {@link AbstractMethodError}.
 * <p>
 * If the JDBC driver does not implement {@link ResultSet#getObject(int, Class)}, then return 0.
 * </p>
 *
 * @param <T>
 *            See {@link ResultSet#getObject(int, Class)}
 * @param resultSet
 *            See {@link ResultSet#getObject(int, Class)}
 * @param columnIndex
 *            See {@link ResultSet#getObject(int, Class)}
 * @param type
 *            See {@link ResultSet#getObject(int, Class)}
 * @return See {@link ResultSet#getObject(int, Class)}
 * @throws SQLException
 *             See {@link ResultSet#getObject(int, Class)}
 * @see ResultSet#getObject(int, Class)
 */
@SuppressWarnings("unchecked")
public static <T> T getObject(final ResultSet resultSet, final int columnIndex, final Class<T> type)
        throws SQLException {
    try {
        return resultSet.getObject(columnIndex, type);
    } catch (final AbstractMethodError e) {
        if (type == String.class) {
            return (T) resultSet.getString(columnIndex);
        }
        // Numbers
        if (type == Integer.class) {
            return (T) Integer.valueOf(resultSet.getInt(columnIndex));
        }
        if (type == Long.class) {
            return (T) Long.valueOf(resultSet.getLong(columnIndex));
        }
        if (type == Double.class) {
            return (T) Double.valueOf(resultSet.getDouble(columnIndex));
        }
        if (type == Float.class) {
            return (T) Float.valueOf(resultSet.getFloat(columnIndex));
        }
        if (type == Short.class) {
            return (T) Short.valueOf(resultSet.getShort(columnIndex));
        }
        if (type == BigDecimal.class) {
            return (T) resultSet.getBigDecimal(columnIndex);
        }
        if (type == Byte.class) {
            return (T) Byte.valueOf(resultSet.getByte(columnIndex));
        }
        // Dates
        if (type == Date.class) {
            return (T) resultSet.getDate(columnIndex);
        }
        if (type == Time.class) {
            return (T) resultSet.getTime(columnIndex);
        }
        if (type == Timestamp.class) {
            return (T) resultSet.getTimestamp(columnIndex);
        }
        // Streams
        if (type == InputStream.class) {
            return (T) resultSet.getBinaryStream(columnIndex);
        }
        if (type == Reader.class) {
            return (T) resultSet.getCharacterStream(columnIndex);
        }
        // Other
        if (type == Object.class) {
            return (T) resultSet.getObject(columnIndex);
        }
        if (type == Boolean.class) {
            return (T) Boolean.valueOf(resultSet.getBoolean(columnIndex));
        }
        if (type == Array.class) {
            return (T) resultSet.getArray(columnIndex);
        }
        if (type == Blob.class) {
            return (T) resultSet.getBlob(columnIndex);
        }
        if (type == Clob.class) {
            return (T) resultSet.getClob(columnIndex);
        }
        if (type == Ref.class) {
            return (T) resultSet.getRef(columnIndex);
        }
        if (type == RowId.class) {
            return (T) resultSet.getRowId(columnIndex);
        }
        if (type == SQLXML.class) {
            return (T) resultSet.getSQLXML(columnIndex);
        }
        if (type == URL.class) {
            return (T) resultSet.getURL(columnIndex);
        }
        throw new SQLFeatureNotSupportedException(
                String.format("resultSet=%s, columnIndex=%,d, type=%s", resultSet, Integer.valueOf(columnIndex), type));
    }
}
 
Example 7
Source File: Jdbc41Bridge.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Delegates to {@link ResultSet#getObject(String, Class)} without throwing a {@link AbstractMethodError}.
 *
 * @param <T>
 *            See {@link ResultSet#getObject(String, Class)}
 * @param resultSet
 *            See {@link ResultSet#getObject(String, Class)}
 * @param columnLabel
 *            See {@link ResultSet#getObject(String, Class)}
 * @param type
 *            See {@link ResultSet#getObject(String, Class)}
 * @return See {@link ResultSet#getObject(String, Class)}
 * @throws SQLException
 *             See {@link ResultSet#getObject(String, Class)}
 * @see ResultSet#getObject(int, Class)
 */
@SuppressWarnings("unchecked")
public static <T> T getObject(final ResultSet resultSet, final String columnLabel, final Class<T> type)
        throws SQLException {
    try {
        return resultSet.getObject(columnLabel, type);
    } catch (final AbstractMethodError e) {
        // Numbers
        if (type == Integer.class) {
            return (T) Integer.valueOf(resultSet.getInt(columnLabel));
        }
        if (type == Long.class) {
            return (T) Long.valueOf(resultSet.getLong(columnLabel));
        }
        if (type == Double.class) {
            return (T) Double.valueOf(resultSet.getDouble(columnLabel));
        }
        if (type == Float.class) {
            return (T) Float.valueOf(resultSet.getFloat(columnLabel));
        }
        if (type == Short.class) {
            return (T) Short.valueOf(resultSet.getShort(columnLabel));
        }
        if (type == BigDecimal.class) {
            return (T) resultSet.getBigDecimal(columnLabel);
        }
        if (type == Byte.class) {
            return (T) Byte.valueOf(resultSet.getByte(columnLabel));
        }
        // Dates
        if (type == Date.class) {
            return (T) resultSet.getDate(columnLabel);
        }
        if (type == Time.class) {
            return (T) resultSet.getTime(columnLabel);
        }
        if (type == Timestamp.class) {
            return (T) resultSet.getTimestamp(columnLabel);
        }
        // Streams
        if (type == InputStream.class) {
            return (T) resultSet.getBinaryStream(columnLabel);
        }
        if (type == Reader.class) {
            return (T) resultSet.getCharacterStream(columnLabel);
        }
        // Other
        if (type == Object.class) {
            return (T) resultSet.getObject(columnLabel);
        }
        if (type == Boolean.class) {
            return (T) Boolean.valueOf(resultSet.getBoolean(columnLabel));
        }
        if (type == Array.class) {
            return (T) resultSet.getArray(columnLabel);
        }
        if (type == Blob.class) {
            return (T) resultSet.getBlob(columnLabel);
        }
        if (type == Clob.class) {
            return (T) resultSet.getClob(columnLabel);
        }
        if (type == Ref.class) {
            return (T) resultSet.getRef(columnLabel);
        }
        if (type == RowId.class) {
            return (T) resultSet.getRowId(columnLabel);
        }
        if (type == SQLXML.class) {
            return (T) resultSet.getSQLXML(columnLabel);
        }
        if (type == URL.class) {
            return (T) resultSet.getURL(columnLabel);
        }
        throw new SQLFeatureNotSupportedException(
                String.format("resultSet=%s, columnLabel=%s, type=%s", resultSet, columnLabel, type));
    }
}
 
Example 8
Source File: AvaticaResultSetConversionsTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
public Object getURL(ResultSet r) throws SQLException {
  return r.getURL(ordinal);
}
 
Example 9
Source File: AvaticaResultSetConversionsTest.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
public URL getURL(ResultSet r) throws SQLException {
  return r.getURL(label);
}
 
Example 10
Source File: UrlSetterMapping.java    From butterfly-persistence with Apache License 2.0 4 votes vote down vote up
protected Object getValueFromResultSetDo(ResultSet result) throws SQLException {
    return result.getURL(getColumnName());
}
 
Example 11
Source File: UrlResultSetGetter.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public URL get(final ResultSet target) throws SQLException {
	return target.getURL(column);
}
 
Example 12
Source File: Jdbc41Bridge.java    From commons-dbcp with Apache License 2.0 4 votes vote down vote up
/**
 * Delegates to {@link ResultSet#getObject(int, Class)} without throwing an {@link AbstractMethodError}.
 * <p>
 * If the JDBC driver does not implement {@link ResultSet#getObject(int, Class)}, then return 0.
 * </p>
 *
 * @param <T>
 *            See {@link ResultSet#getObject(int, Class)}
 * @param resultSet
 *            See {@link ResultSet#getObject(int, Class)}
 * @param columnIndex
 *            See {@link ResultSet#getObject(int, Class)}
 * @param type
 *            See {@link ResultSet#getObject(int, Class)}
 * @return See {@link ResultSet#getObject(int, Class)}
 * @throws SQLException
 *             See {@link ResultSet#getObject(int, Class)}
 * @see ResultSet#getObject(int, Class)
 */
@SuppressWarnings("unchecked")
public static <T> T getObject(final ResultSet resultSet, final int columnIndex, final Class<T> type)
        throws SQLException {
    try {
        return resultSet.getObject(columnIndex, type);
    } catch (final AbstractMethodError e) {
        if (type == String.class) {
            return (T) resultSet.getString(columnIndex);
        }
        // Numbers
        if (type == Integer.class) {
            return (T) Integer.valueOf(resultSet.getInt(columnIndex));
        }
        if (type == Long.class) {
            return (T) Long.valueOf(resultSet.getLong(columnIndex));
        }
        if (type == Double.class) {
            return (T) Double.valueOf(resultSet.getDouble(columnIndex));
        }
        if (type == Float.class) {
            return (T) Float.valueOf(resultSet.getFloat(columnIndex));
        }
        if (type == Short.class) {
            return (T) Short.valueOf(resultSet.getShort(columnIndex));
        }
        if (type == BigDecimal.class) {
            return (T) resultSet.getBigDecimal(columnIndex);
        }
        if (type == Byte.class) {
            return (T) Byte.valueOf(resultSet.getByte(columnIndex));
        }
        // Dates
        if (type == Date.class) {
            return (T) resultSet.getDate(columnIndex);
        }
        if (type == Time.class) {
            return (T) resultSet.getTime(columnIndex);
        }
        if (type == Timestamp.class) {
            return (T) resultSet.getTimestamp(columnIndex);
        }
        // Streams
        if (type == InputStream.class) {
            return (T) resultSet.getBinaryStream(columnIndex);
        }
        if (type == Reader.class) {
            return (T) resultSet.getCharacterStream(columnIndex);
        }
        // Other
        if (type == Object.class) {
            return (T) resultSet.getObject(columnIndex);
        }
        if (type == Boolean.class) {
            return (T) Boolean.valueOf(resultSet.getBoolean(columnIndex));
        }
        if (type == Array.class) {
            return (T) resultSet.getArray(columnIndex);
        }
        if (type == Blob.class) {
            return (T) resultSet.getBlob(columnIndex);
        }
        if (type == Clob.class) {
            return (T) resultSet.getClob(columnIndex);
        }
        if (type == Ref.class) {
            return (T) resultSet.getRef(columnIndex);
        }
        if (type == RowId.class) {
            return (T) resultSet.getRowId(columnIndex);
        }
        if (type == SQLXML.class) {
            return (T) resultSet.getSQLXML(columnIndex);
        }
        if (type == URL.class) {
            return (T) resultSet.getURL(columnIndex);
        }
        throw new SQLFeatureNotSupportedException(
                String.format("resultSet=%s, columnIndex=%,d, type=%s", resultSet, columnIndex, type));
    }
}
 
Example 13
Source File: Jdbc41Bridge.java    From commons-dbcp with Apache License 2.0 4 votes vote down vote up
/**
 * Delegates to {@link ResultSet#getObject(String, Class)} without throwing an {@link AbstractMethodError}.
 *
 * @param <T>
 *            See {@link ResultSet#getObject(String, Class)}
 * @param resultSet
 *            See {@link ResultSet#getObject(String, Class)}
 * @param columnLabel
 *            See {@link ResultSet#getObject(String, Class)}
 * @param type
 *            See {@link ResultSet#getObject(String, Class)}
 * @return See {@link ResultSet#getObject(String, Class)}
 * @throws SQLException
 *             See {@link ResultSet#getObject(String, Class)}
 * @see ResultSet#getObject(int, Class)
 */
@SuppressWarnings("unchecked")
public static <T> T getObject(final ResultSet resultSet, final String columnLabel, final Class<T> type)
        throws SQLException {
    try {
        return resultSet.getObject(columnLabel, type);
    } catch (final AbstractMethodError e) {
        // Numbers
        if (type == Integer.class) {
            return (T) Integer.valueOf(resultSet.getInt(columnLabel));
        }
        if (type == Long.class) {
            return (T) Long.valueOf(resultSet.getLong(columnLabel));
        }
        if (type == Double.class) {
            return (T) Double.valueOf(resultSet.getDouble(columnLabel));
        }
        if (type == Float.class) {
            return (T) Float.valueOf(resultSet.getFloat(columnLabel));
        }
        if (type == Short.class) {
            return (T) Short.valueOf(resultSet.getShort(columnLabel));
        }
        if (type == BigDecimal.class) {
            return (T) resultSet.getBigDecimal(columnLabel);
        }
        if (type == Byte.class) {
            return (T) Byte.valueOf(resultSet.getByte(columnLabel));
        }
        // Dates
        if (type == Date.class) {
            return (T) resultSet.getDate(columnLabel);
        }
        if (type == Time.class) {
            return (T) resultSet.getTime(columnLabel);
        }
        if (type == Timestamp.class) {
            return (T) resultSet.getTimestamp(columnLabel);
        }
        // Streams
        if (type == InputStream.class) {
            return (T) resultSet.getBinaryStream(columnLabel);
        }
        if (type == Reader.class) {
            return (T) resultSet.getCharacterStream(columnLabel);
        }
        // Other
        if (type == Object.class) {
            return (T) resultSet.getObject(columnLabel);
        }
        if (type == Boolean.class) {
            return (T) Boolean.valueOf(resultSet.getBoolean(columnLabel));
        }
        if (type == Array.class) {
            return (T) resultSet.getArray(columnLabel);
        }
        if (type == Blob.class) {
            return (T) resultSet.getBlob(columnLabel);
        }
        if (type == Clob.class) {
            return (T) resultSet.getClob(columnLabel);
        }
        if (type == Ref.class) {
            return (T) resultSet.getRef(columnLabel);
        }
        if (type == RowId.class) {
            return (T) resultSet.getRowId(columnLabel);
        }
        if (type == SQLXML.class) {
            return (T) resultSet.getSQLXML(columnLabel);
        }
        if (type == URL.class) {
            return (T) resultSet.getURL(columnLabel);
        }
        throw new SQLFeatureNotSupportedException(
                String.format("resultSet=%s, columnLabel=%s, type=%s", resultSet, columnLabel, type));
    }
}