Example usage for java.sql ResultSet getFloat

List of usage examples for java.sql ResultSet getFloat

Introduction

In this page you can find the example usage for java.sql ResultSet getFloat.

Prototype

float getFloat(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a float in the Java programming language.

Usage

From source file:GestoSAT.GestoSAT.java

public boolean actualizarStock(int id, float cantidad) {
    try {//from w ww.  j a v  a  2 s. c o  m
        Class.forName("com.mysql.jdbc.Driver");
        Statement st = con.createStatement();
        ResultSet res = st.executeQuery("Select Unidades From stock Where id_Stock='" + id + "'");

        if (res.next()) {
            if (st.executeUpdate("Update stock SET Unidades='" + (Math.abs(cantidad) + res.getFloat("Unidades"))
                    + "' Where id_Stock='" + id + "'") > 0)
                return true;
            else
                return false;
        } else
            return false;

    } catch (Exception ex) {
        Logger.getLogger(GestoSAT.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
}

From source file:Logica.Usuario.java

/**
 *
 * @param mes/*from w  w w .j  a v  a2 s. co m*/
 * @return
 * @throws RemoteException
 *
 * Genera el informe de descargos de acuerdo al mes ingresado
 */
@Override
public ArrayList<informeDescargos> generarInforme(String mes) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    String statement = "create view gInforme1 as(select i.CINTERNO, i.INVENTARIO, i.DESCRIPCION, i.CANTIDAD as enInventario, d.FECHA as fecha, (select nombre from usuario where id = d.id_usuario) as nombre ,d.id_usuario as id, d.AREA\n"
            + "from item  i right outer join DESCARGO d\n" + "on i.CINTERNO = d.CINTERNO);";
    String statement2 = "create view gInforme2 as( select cinterno, inventario, descripcion, eninventario, fecha, nombre, id, area from gInforme1 where gInforme1.fecha like ?);";
    String statement3 = "create view gInforme3 as(select d.CINTERNO, \"\",sum(d.cantidad) as suma from descargo d, descargo dd where dd.id= d.id group by d.CINTERNO);";
    String statement4 = "select distinct  p2.cinterno, p2.inventario, p2.descripcion, p2.eninventario, p3.suma, p2.nombre, p2.id, p2.area\n"
            + " from gInforme2 p2 , gInforme3 p3 where p2.cinterno = p3.CINTERNO; ";
    informeDescargos fila = null;
    ArrayList<informeDescargos> listado = new ArrayList<>();

    System.out.println(statement);
    System.out.println(statement2);
    System.out.println(statement3);
    System.out.println(statement4);
    try {
        con = Conexion.conexion.getConnection();
        mes = "%-" + mes + "-%";
        ps = con.prepareStatement(statement);
        ps.executeUpdate();
        ps = con.prepareStatement(statement2);
        ps.setString(1, mes);
        ps.executeUpdate();
        ps = con.prepareStatement(statement3);
        ps.executeUpdate();
        ps = con.prepareStatement(statement4);
        rs = ps.executeQuery();
        while (rs.next()) {
            fila = new informeDescargos(rs.getString(1), rs.getString(2), rs.getString(3), rs.getFloat(4),
                    rs.getFloat(5), rs.getString(6), rs.getBigDecimal(7), rs.getString(8));
            listado.add(fila);
        }
        ps.executeUpdate("drop view gInforme1;");
        ps.executeUpdate("drop view gInforme2;");
        ps.executeUpdate("drop view gInforme3;");

    } catch (SQLException ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

        try {
            if (ps != null) {
                ps.close();
            }
            if (rs != null) {
                rs.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException ex) {
            System.out.println("Error cerrando conexion");
        }
    }
    return listado;
}

From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java

@SuppressWarnings("deprecation")
private void assertNonExistingColumn(final ResultSet rs) throws Exception {
    int nonExistingColIndex = Integer.MAX_VALUE;
    String nonExistingColName = "col" + nonExistingColIndex;

    try {/*  w ww  . j  av a2 s  .  c  o  m*/
        rs.getString(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getString(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBoolean(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBoolean(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getByte(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getByte(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getShort(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getShort(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(nonExistingColIndex, 1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(nonExistingColName, 1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(nonExistingColIndex, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(nonExistingColName, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(nonExistingColIndex, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(nonExistingColName, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(nonExistingColIndex, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(nonExistingColName, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getUnicodeStream(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getUnicodeStream(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream(nonExistingColIndex);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream(nonExistingColName);
        fail();
    } catch (SQLException ignore) {
    }

}

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

@Test
public void testInt() throws SQLException {
    trace("test INT");
    ResultSet rs;
    Object o;/*from  w w  w. ja  va  2 s .  c  o m*/
    stat = conn.createStatement();
    stat.execute("INSERT INTO test (column1,column2,column3) VALUES(31,-1, 'testInt')");
    stat.execute("INSERT INTO test (column1,column2,column3) VALUES(32,0, 'testInt')");
    stat.execute("INSERT INTO test (column1,column2,column3) VALUES(33,1, 'testInt')");
    stat.execute("INSERT INTO test (column1,column2,column3) VALUES(34," + Integer.MAX_VALUE + ", 'testInt')");
    stat.execute("INSERT INTO test (column1,column2,column3) VALUES(35," + Integer.MIN_VALUE + ", 'testInt')");
    stat.execute("INSERT INTO test (column1,column2,column3) VALUES(36,0, 'testInt')");
    stat.execute("INSERT INTO test (column1,column2,column3) VALUES(37,0, 'testInt')");
    // this should not be read - maxrows=6

    // MySQL compatibility (is this required?)
    rs = stat.executeQuery("SELECT column1,column2,column3 FROM test where column3='testInt' ORDER BY column1");
    // MySQL compatibility
    assertEquals(1, rs.findColumn("column1"));
    assertEquals(2, rs.findColumn("column2"));

    ResultSetMetaData meta = rs.getMetaData();
    assertEquals(3, meta.getColumnCount());

    assertTrue(rs.getRow() == 0);

    rs.next();
    trace("default fetch size=" + rs.getFetchSize());
    // 0 should be an allowed value (but it's not defined what is actually
    // means)
    rs.setFetchSize(1);
    assertThrows(SQLErrorCode.INVALID_VALUE_2, rs).setFetchSize(-1);
    // fetch size 100 is bigger than maxrows - not allowed
    rs.setFetchSize(6);

    assertTrue(rs.getRow() == 1);
    assertEquals(2, rs.findColumn("COLUMN2"));
    assertEquals(2, rs.findColumn("column2"));
    assertEquals(2, rs.findColumn("Column2"));
    assertEquals(1, rs.findColumn("COLUMN1"));
    assertEquals(1, rs.findColumn("column1"));
    assertEquals(1, rs.findColumn("Column1"));
    assertEquals(1, rs.findColumn("colUMN1"));
    assertTrue(rs.getInt(2) == -1 && !rs.wasNull());
    assertTrue(rs.getInt("COLUMN2") == -1 && !rs.wasNull());
    assertTrue(rs.getInt("column2") == -1 && !rs.wasNull());
    assertTrue(rs.getInt("Column2") == -1 && !rs.wasNull());
    assertTrue(rs.getString("Column2").equals("-1") && !rs.wasNull());

    o = rs.getObject("column2");
    trace(o.getClass().getName());
    assertTrue(o instanceof Long);
    assertTrue(((Long) o).longValue() == -1);
    o = rs.getObject(2);
    trace(o.getClass().getName());
    assertTrue(o instanceof Long);
    assertTrue(((Long) o).longValue() == -1);
    assertTrue(rs.getBoolean("Column2"));
    assertTrue(rs.getByte("Column2") == (byte) -1);
    assertTrue(rs.getShort("Column2") == (short) -1);
    assertTrue(rs.getLong("Column2") == -1);
    assertTrue(rs.getFloat("Column2") == -1.0);
    assertTrue(rs.getDouble("Column2") == -1.0);

    assertTrue(rs.getString("Column2").equals("-1") && !rs.wasNull());
    assertTrue(rs.getInt("COLUMN1") == 31 && !rs.wasNull());
    assertTrue(rs.getInt("column1") == 31 && !rs.wasNull());
    assertTrue(rs.getInt("Column1") == 31 && !rs.wasNull());
    assertTrue(rs.getInt(1) == 31 && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 2);
    assertTrue(rs.getInt(2) == 0 && !rs.wasNull());
    assertTrue(!rs.getBoolean(2));
    assertTrue(rs.getByte(2) == 0);
    assertTrue(rs.getShort(2) == 0);
    assertTrue(rs.getLong(2) == 0);
    assertTrue(rs.getFloat(2) == 0.0);
    assertTrue(rs.getDouble(2) == 0.0);
    assertTrue(rs.getString(2).equals("0") && !rs.wasNull());
    assertTrue(rs.getInt(1) == 32 && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 3);
    assertTrue(rs.getInt("COLUMN1") == 33 && !rs.wasNull());
    assertTrue(rs.getInt("COLUMN2") == 1 && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 4);
    assertTrue(rs.getInt("COLUMN1") == 34 && !rs.wasNull());
    assertTrue(rs.getInt("COLUMN2") == Integer.MAX_VALUE && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 5);
    assertTrue(rs.getInt("column1") == 35 && !rs.wasNull());
    assertTrue(rs.getInt("column2") == Integer.MIN_VALUE && !rs.wasNull());
    assertTrue(rs.getString(1).equals("35") && !rs.wasNull());
    rs.next();
    assertTrue(rs.getRow() == 6);
    assertTrue(rs.getInt("column1") == 36 && !rs.wasNull());
    assertTrue(rs.getInt("column2") == 0 && !rs.wasNull());
    assertTrue(rs.getInt(2) == 0 && !rs.wasNull());
    assertTrue(rs.getInt(1) == 36 && !rs.wasNull());
    assertTrue(rs.getString(1).equals("36") && !rs.wasNull());
    assertTrue(rs.getString(2).equals("0") && !rs.wasNull());
    assertTrue(!rs.wasNull());
    // assertFalse(rs.next());
    // assertEquals(0, rs.getRow());
    // there is one more row, but because of setMaxRows we don't get it
}

From source file:ProcessRequest.java

public JSONArray parseQueryResults(ResultSet rs, String table) throws SQLException, JSONException {
    JSONArray resultJSONArray = new JSONArray();
    ResultSetMetaData rsmd = rs.getMetaData();
    int columns = rsmd.getColumnCount();
    while (rs.next()) {
        JSONObject result = new JSONObject();
        JSONObject resultMeta = new JSONObject();
        resultMeta.put("table", table);
        result.put("metadata", resultMeta);
        for (int i = 1; i <= columns; i++) {
            //out.println("<td>"+rs.getString(i)+"</td>");
            int type = rsmd.getColumnType(i);
            //result.put(rsmd.getColumnName(i), rs.get)
            switch (type) {
            case Types.BIT:
                result.put(rsmd.getColumnName(i), rs.getBoolean(i));
                break;
            case Types.TINYINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.SMALLINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.INTEGER:
                //System.out.println(rsmd.getColumnName(i) + "  type: "+type);
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.BIGINT:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.FLOAT:
                result.put(rsmd.getColumnName(i), rs.getFloat(i));
                break;
            case Types.REAL:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.DOUBLE:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.NUMERIC:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.DECIMAL:
                result.put(rsmd.getColumnName(i), rs.getDouble(i));
                break;
            case Types.CHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.VARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.LONGVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.DATE: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }//from   ww  w .  j  a va 2  s .  c om
            case Types.TIME: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }
            case Types.TIMESTAMP: {
                java.util.Date date = rs.getDate(i);
                result.put(rsmd.getColumnName(i), date.getTime());
                break;
            }
            case Types.BINARY:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.VARBINARY:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.LONGVARBINARY:
                result.put(rsmd.getColumnName(i), rs.getLong(i));
                break;
            case Types.NULL:
                result.put(rsmd.getColumnName(i), "");
                break;
            case Types.BOOLEAN:
                result.put(rsmd.getColumnName(i), rs.getBoolean(i));
                break;
            case Types.ROWID:
                result.put(rsmd.getColumnName(i), rs.getInt(i));
                break;
            case Types.NCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.NVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.LONGNVARCHAR:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            case Types.SQLXML:
            case Types.NCLOB:
            case Types.DATALINK:
            case Types.REF:
            case Types.OTHER:
            case Types.JAVA_OBJECT:
            case Types.DISTINCT:
            case Types.STRUCT:
            case Types.ARRAY:
            case Types.BLOB:
            case Types.CLOB:
            default:
                result.put(rsmd.getColumnName(i), rs.getString(i));
                break;
            }
        }
        //if(table.equals("Ticket"))
        //System.out.println(result.toString(5));
        resultJSONArray.put(result);
    }
    return resultJSONArray;
}

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

@Test
public void testDoubleFloat() throws SQLException, IOException {
    trace("test DOUBLE - FLOAT");

    ResultInHBasePrinter.printFMETA(TEST_UTIL.getConfiguration(), LOG);
    ResultInHBasePrinter.printMETA(TEST_UTIL.getConfiguration(), LOG);
    ResultSet rs;
    Object o;//from ww  w  .j a  v a 2s .c  o  m

    stat = conn.createStatement();
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(11, -1, -1, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(12,.0, .0, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(13, 1., 1., 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(14, 12345678.89, 12345678.89, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(15, 99999999.99, 99999999.99, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(16, -99999999.99, -99999999.99, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(17, -99999999.99, -99999999.99, 2, 'testDoubleFloat')");
    // stat.execute("INSERT INTO test (column1,column5,column4,column2,column3) VALUES(8, NULL, NULL, 2, 'testDoubleFloat')");

    rs = stat.executeQuery(
            "SELECT column1,column5,column4 FROM test where column3='testDoubleFloat'  ORDER BY column1");
    // assertResultSetMeta(rs, 3, new String[] { "ID", "D", "R" }, new int[] {
    // Types.INTEGER, Types.DOUBLE, Types.REAL }, new int[] { 10, 17, 7 },
    // new int[] { 0, 0, 0 });
    BigDecimal bd;
    rs.next();
    assertTrue(rs.getInt(1) == 11);
    assertTrue(!rs.wasNull());
    assertTrue(rs.getInt(2) == -1);
    assertTrue(rs.getInt(3) == -1);
    assertTrue(!rs.wasNull());
    bd = rs.getBigDecimal(2);
    assertTrue(bd.compareTo(new BigDecimal("-1.00")) == 0);
    assertTrue(!rs.wasNull());
    o = rs.getObject(2);
    trace(o.getClass().getName());
    assertTrue(o instanceof Double);
    assertTrue(((Double) o).compareTo(new Double("-1.00")) == 0);
    o = rs.getObject(3);
    trace(o.getClass().getName());
    assertTrue(o instanceof Float);
    assertTrue(((Float) o).compareTo(new Float("-1.00")) == 0);
    rs.next();
    assertTrue(rs.getInt(1) == 12);
    assertTrue(!rs.wasNull());
    assertTrue(rs.getInt(2) == 0);
    assertTrue(!rs.wasNull());
    assertTrue(rs.getInt(3) == 0);
    assertTrue(!rs.wasNull());
    bd = rs.getBigDecimal(2);
    assertTrue(bd.compareTo(new BigDecimal("0.00")) == 0);
    assertTrue(!rs.wasNull());
    bd = rs.getBigDecimal(3);
    assertTrue(bd.compareTo(new BigDecimal("0.00")) == 0);
    assertTrue(!rs.wasNull());
    rs.next();
    assertEquals(1.0, rs.getDouble(2));
    assertEquals(1.0f, rs.getFloat(3));
    rs.next();
    assertEquals(12345678.89, rs.getDouble(2));
    assertEquals(12345678.89f, rs.getFloat(3));
    rs.next();
    assertEquals(99999999.99, rs.getDouble(2));
    assertEquals(99999999.99f, rs.getFloat(3));
    rs.next();
    assertEquals(-99999999.99, rs.getDouble(2));
    assertEquals(-99999999.99f, rs.getFloat(3));
    // rs.next();
    // checkColumnBigDecimal(rs, 2, 0, null);
    // checkColumnBigDecimal(rs, 3, 0, null);
    // assertTrue(!rs.next());
    // stat.execute("DROP TABLE test");
}

From source file:org.wso2.carbon.dataservices.core.odata.RDBMSDataHandler.java

private String getValueFromResultSet(int columnType, String column, ResultSet resultSet) throws SQLException {
    String paramValue;/*from   w w  w .  ja  va2 s .c  om*/
    switch (columnType) {
    case Types.INTEGER:
        /* fall through */
    case Types.TINYINT:
        /* fall through */
    case Types.SMALLINT:
        paramValue = ConverterUtil.convertToString(resultSet.getInt(column));
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    case Types.DOUBLE:
        paramValue = ConverterUtil.convertToString(resultSet.getDouble(column));
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    case Types.VARCHAR:
        /* fall through */
    case Types.CHAR:
        /* fall through */
    case Types.CLOB:
        /* fall through */
    case Types.LONGVARCHAR:
        paramValue = resultSet.getString(column);
        break;
    case Types.BOOLEAN:
        /* fall through */
    case Types.BIT:
        paramValue = ConverterUtil.convertToString(resultSet.getBoolean(column));
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    case Types.BLOB:
        Blob sqlBlob = resultSet.getBlob(column);
        if (sqlBlob != null) {
            paramValue = this.getBase64StringFromInputStream(sqlBlob.getBinaryStream());
        } else {
            paramValue = null;
        }
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    case Types.BINARY:
        /* fall through */
    case Types.LONGVARBINARY:
        /* fall through */
    case Types.VARBINARY:
        InputStream binInStream = resultSet.getBinaryStream(column);
        if (binInStream != null) {
            paramValue = this.getBase64StringFromInputStream(binInStream);
        } else {
            paramValue = null;
        }
        break;
    case Types.DATE:
        Date sqlDate = resultSet.getDate(column);
        if (sqlDate != null) {
            paramValue = ConverterUtil.convertToString(sqlDate);
        } else {
            paramValue = null;
        }
        break;
    case Types.DECIMAL:
        /* fall through */
    case Types.NUMERIC:
        BigDecimal bigDecimal = resultSet.getBigDecimal(column);
        if (bigDecimal != null) {
            paramValue = ConverterUtil.convertToString(bigDecimal);
        } else {
            paramValue = null;
        }
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    case Types.FLOAT:
        paramValue = ConverterUtil.convertToString(resultSet.getFloat(column));
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    case Types.TIME:
        Time sqlTime = resultSet.getTime(column);
        if (sqlTime != null) {
            paramValue = this.convertToTimeString(sqlTime);
        } else {
            paramValue = null;
        }
        break;
    case Types.LONGNVARCHAR:
        /* fall through */
    case Types.NCHAR:
        /* fall through */
    case Types.NCLOB:
        /* fall through */
    case Types.NVARCHAR:
        paramValue = resultSet.getNString(column);
        break;
    case Types.BIGINT:
        paramValue = ConverterUtil.convertToString(resultSet.getLong(column));
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    case Types.TIMESTAMP:
        Timestamp sqlTimestamp = resultSet.getTimestamp(column);
        if (sqlTimestamp != null) {
            paramValue = this.convertToTimestampString(sqlTimestamp);
        } else {
            paramValue = null;
        }
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    /* handle all other types as strings */
    default:
        paramValue = resultSet.getString(column);
        paramValue = resultSet.wasNull() ? null : paramValue;
        break;
    }
    return paramValue;
}

From source file:GestoSAT.GestoSAT.java

public Map getStock() {

    try {/*from  w  w  w .j a  va2  s  .  c om*/
        Map stock = new HashMap();
        Class.forName("com.mysql.jdbc.Driver");
        Statement st = con.createStatement();
        ResultSet res = st.executeQuery(
                "Select * From stock S INNER JOIN proveedores P ON S.id_proveedor = P.id_Proveedor");
        Proveedor p;
        this.getProveedores();
        while (res.next()) {
            p = (Proveedor) this.proveedor.get(res.getInt("P.id_Proveedor"));
            Stock s = new Stock(res.getString("S.Nombre"), res.getFloat("S.Unidades"),
                    res.getFloat("S.Precio_venta"), (String) res.getObject("S.Descripcion"),
                    res.getFloat("S.Precio_compra"), res.getFloat("S.num_Alertar"), p);
            s = p.setStock(res.getInt("s.id_Stock"), s);
            stock.putIfAbsent(res.getInt("S.id_Stock"), s);
        }
        return stock;
    } catch (Exception ex) {
        Logger.getLogger(GestoSAT.class.getName()).log(Level.SEVERE, null, ex);
        return new HashMap();
    }
}

From source file:com.l2jfree.gameserver.datatables.NpcTable.java

private boolean fillNpcTable(ResultSet NpcData) throws Exception {
    boolean loaded = false;
    while (NpcData.next()) {
        StatsSet npcDat = new StatsSet();
        int id = NpcData.getInt("id");

        if (Config.ASSERT)
            assert id < 1000000;

        npcDat.set("npcId", id);
        npcDat.set("idTemplate", NpcData.getInt("idTemplate"));
        int level = NpcData.getInt("level");
        npcDat.set("level", level);
        npcDat.set("jClass", NpcData.getString("class"));

        npcDat.set("baseShldDef", 0);
        npcDat.set("baseShldRate", 0);
        npcDat.set("baseCritRate", 38);

        npcDat.set("name", NpcData.getString("name"));
        npcDat.set("serverSideName", NpcData.getBoolean("serverSideName"));
        npcDat.set("title", NpcData.getString("title"));
        npcDat.set("serverSideTitle", NpcData.getBoolean("serverSideTitle"));
        npcDat.set("collision_radius", NpcData.getDouble("collision_radius"));
        npcDat.set("collision_height", NpcData.getDouble("collision_height"));
        npcDat.set("fcollision_radius", NpcData.getDouble("collision_radius"));
        npcDat.set("fcollision_height", NpcData.getDouble("collision_height"));
        npcDat.set("sex", NpcData.getString("sex"));
        if (!Config.ALLOW_NPC_WALKERS && NpcData.getString("type").equalsIgnoreCase("L2NpcWalker"))
            npcDat.set("type", "L2Npc");
        else// w w w. ja v  a2s .  c o m
            npcDat.set("type", NpcData.getString("type"));
        npcDat.set("baseAtkRange", NpcData.getInt("attackrange"));
        npcDat.set("rewardExp", NpcData.getInt("exp"));
        npcDat.set("rewardSp", NpcData.getInt("sp"));
        npcDat.set("basePAtkSpd", NpcData.getInt("atkspd"));
        npcDat.set("baseMAtkSpd", NpcData.getInt("matkspd"));
        npcDat.set("aggroRange", NpcData.getInt("aggro"));
        npcDat.set("rhand", NpcData.getInt("rhand"));
        npcDat.set("lhand", NpcData.getInt("lhand"));
        npcDat.set("armor", NpcData.getInt("armor"));
        npcDat.set("baseWalkSpd", NpcData.getInt("walkspd"));
        npcDat.set("baseRunSpd", NpcData.getInt("runspd"));

        npcDat.safeSet("baseSTR", NpcData.getInt("str"), 0, Formulas.MAX_STAT_VALUE,
                "Loading NPC template; ID: " + npcDat.getString("idTemplate"));
        npcDat.safeSet("baseCON", NpcData.getInt("con"), 0, Formulas.MAX_STAT_VALUE,
                "Loading NPC template; ID: " + npcDat.getString("idTemplate"));
        npcDat.safeSet("baseDEX", NpcData.getInt("dex"), 0, Formulas.MAX_STAT_VALUE,
                "Loading NPC template; ID: " + npcDat.getString("idTemplate"));
        npcDat.safeSet("baseINT", NpcData.getInt("int"), 0, Formulas.MAX_STAT_VALUE,
                "Loading NPC template; ID: " + npcDat.getString("idTemplate"));
        npcDat.safeSet("baseWIT", NpcData.getInt("wit"), 0, Formulas.MAX_STAT_VALUE,
                "Loading NPC template; ID: " + npcDat.getString("idTemplate"));
        npcDat.safeSet("baseMEN", NpcData.getInt("men"), 0, Formulas.MAX_STAT_VALUE,
                "Loading NPC template; ID: " + npcDat.getString("idTemplate"));

        npcDat.set("baseHpMax", NpcData.getInt("hp"));
        npcDat.set("baseCpMax", 0);
        npcDat.set("baseMpMax", NpcData.getInt("mp"));
        npcDat.set("baseHpReg",
                NpcData.getFloat("hpreg") > 0 ? NpcData.getFloat("hpreg") : 1.5 + ((level - 1) / 10.0));
        npcDat.set("baseMpReg",
                NpcData.getFloat("mpreg") > 0 ? NpcData.getFloat("mpreg") : 0.9 + 0.3 * ((level - 1) / 10.0));
        npcDat.set("basePAtk", NpcData.getInt("patk"));
        npcDat.set("basePDef", NpcData.getInt("pdef"));
        npcDat.set("baseMAtk", NpcData.getInt("matk"));
        npcDat.set("baseMDef", NpcData.getInt("mdef"));

        npcDat.set("factionId", NpcData.getString("faction_id"));
        npcDat.set("factionRange", NpcData.getInt("faction_range"));

        npcDat.set("isUndead", NpcData.getString("isUndead"));

        npcDat.set("absorb_level", NpcData.getString("absorb_level"));
        npcDat.set("absorb_type", NpcData.getString("absorb_type"));

        npcDat.set("ss", NpcData.getInt("ss"));
        npcDat.set("bss", NpcData.getInt("bss"));
        npcDat.set("ssRate", NpcData.getInt("ss_rate"));

        npcDat.set("AI", NpcData.getString("AI"));
        npcDat.set("drop_herbs", Boolean.valueOf(NpcData.getString("drop_herbs")));

        if (Config.FACTION_ENABLED) {
            Faction faction;
            for (int i = 0; i < FactionManager.getInstance().getFactions().size(); i++) {
                faction = FactionManager.getInstance().getFactions().get(i);
                if (faction.getNpcList().contains(id)) {
                    npcDat.set("NPCFaction", faction.getId());
                    npcDat.set("NPCFactionName", faction.getName());
                }
            }
        }

        L2NpcTemplate template = new L2NpcTemplate(npcDat);
        template.addVulnerability(Stats.BOW_WPN_VULN, 1);
        template.addVulnerability(Stats.CROSSBOW_WPN_VULN, 1);
        template.addVulnerability(Stats.BLUNT_WPN_VULN, 1);
        template.addVulnerability(Stats.DAGGER_WPN_VULN, 1);

        _npcs.set(id, template);

        loaded = true;
    }
    return loaded;
}

From source file:Logica.Usuario.java

/**
 *
 * @return ArrayList//from w  ww. java  2  s  .  co  m
 * @throws RemoteException
 *
 * Devuelve un listado con los ltimos tems que han sido ingresados.
 */
@Override
public ArrayList<ItemInventario> ultimos() throws RemoteException {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    String numero;
    String lab;
    String descripcion;
    String presentacion;
    float cantidad;
    float precio;
    String cCalidad;
    String cEsp;
    String sucursal;
    ItemInventario in;
    ArrayList<ItemInventario> lista = new ArrayList<>();
    try {
        con = Conexion.conexion.getConnection();
        String statement = "(select * from item where cinterno like '%MMC%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%MT%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%AS%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%B%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%ER%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%I%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%MT%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%MV%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%N%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%PL%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%T%' order by CINTERNO desc limit 1)\n"
                + "union\n" + "(select * from item where cinterno like '%V%' order by CINTERNO desc limit 1)";
        ps = con.prepareStatement(statement);
        rs = ps.executeQuery();
        while (rs.next()) {
            numero = rs.getString("CINTERNO");
            lab = rs.getString("INVENTARIO");
            descripcion = rs.getString("DESCRIPCION");
            presentacion = rs.getString("PRESENTACION");
            cantidad = rs.getFloat("CANTIDAD");
            precio = rs.getFloat("PRECIO");
            cCalidad = rs.getString("CCALIDAD");
            cEsp = rs.getString("CESP");
            in = new ItemInventario(numero, lab, descripcion, presentacion, cantidad, precio, cCalidad, cEsp,
                    "", new Float(0));
            lista.add(in);
        }
    } catch (SQLException ex) {
        System.out.println("Error en la funcin \"CVer ltimos\"");
    } finally {

        try {
            if (ps != null) {
                ps.close();
            }
            if (rs != null) {
                rs.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException ex) {
            System.out.println("Error cerrando la conexin");
        }
    }

    return lista;

}