Here you can find the source of getBigObject(ResultSet set, int columnIndex)
Parameter | Description |
---|---|
set | a parameter |
columnIndex | a parameter |
Parameter | Description |
---|---|
SQLException | an exception |
IOException | an exception |
public static Object getBigObject(ResultSet set, int columnIndex) throws SQLException
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; import java.sql.Clob; import java.sql.ResultSet; import java.sql.SQLException; public class Main { private static final String NULLDATE = "0000-00-00 00:00:00"; /**//from w w w . j av a2 s .c o m * * Get Object by special column index * * @param set * @param columnIndex * @return * @throws SQLException * @throws IOException */ public static Object getBigObject(ResultSet set, int columnIndex) throws SQLException { Object object = null; try { object = set.getObject(columnIndex); if (object != null && object instanceof Clob) { Reader is = ((Clob) object).getCharacterStream(); BufferedReader br = new BufferedReader(is); String str = br.readLine(); StringBuffer sb = new StringBuffer(); while (str != null) { sb.append(str); str = br.readLine(); } return sb.toString(); } } catch (SQLException e) { if (NULLDATE.equals(set.getString(columnIndex))) { object = null; } else { throw e; } } catch (IOException e) { object = null; } return object; } /** * * Get Object by special column index * * @param set * @param columnIndex * @return * @throws SQLException * @throws IOException */ public static Object getBigObject(ResultSet set, String columnName) throws SQLException { Object object = null; try { object = set.getObject(columnName); if (object != null && object instanceof Clob) { Reader is = ((Clob) object).getCharacterStream(); BufferedReader br = new BufferedReader(is); String str = br.readLine(); StringBuffer sb = new StringBuffer(); while (str != null) { sb.append(str); str = br.readLine(); } return sb.toString(); } } catch (SQLException e) { if (NULLDATE.equals(set.getString(columnName))) { object = null; } else { throw e; } } catch (IOException e) { object = null; } return object; } /** * * Get Object by special column index * * @param set * @param columnIndex * @return * @throws SQLException */ public static Object getObject(ResultSet set, int columnIndex) throws SQLException { Object object = null; try { object = set.getObject(columnIndex); } catch (SQLException e) { if (NULLDATE.equals(set.getString(columnIndex))) { object = null; } else { throw e; } } return object; } /** * * Get Object by special column name * * @param set * @param columnName * @return * @throws SQLException */ public static Object getObject(ResultSet set, String columnName) throws SQLException { Object object = null; try { object = set.getObject(columnName); } catch (SQLException e) { if (NULLDATE.equals(set.getString(columnName))) { object = null; } else { throw e; } } return object; } }