List of usage examples for java.sql Types DOUBLE
int DOUBLE
To view the source code for java.sql Types DOUBLE.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DOUBLE
.
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 w ww . j ava 2 s .c o m*/ 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:ProcessRequest.java
public void parseQueryResults(ResultSet rs, String table, OutputStream os, boolean append) throws SQLException, JSONException, IOException { //JSONArray resultJSONArray = new JSONArray(); ResultSetMetaData rsmd = rs.getMetaData(); int columns = rsmd.getColumnCount(); rs.last();//from w w w . j a va2 s . c o m int rows = rs.getRow(); os.write(new String("total rows: " + rows).getBytes()); rs.first(); int rowCount = 0; while (rs.next()) { if (!rs.isFirst() || append) { os.write(new String(",\n").getBytes()); os.write(new String("" + rowCount).getBytes()); } if (rowCount >= 69) System.out.println("break point"); rowCount++; 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; } 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)); //if(result.getInt("TicketNumber")==126868) // System.out.println("break point"); //resultJSONArray.put(result); os.write(result.toString(5).getBytes()); } //return resultJSONArray; }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Indicates whether the given SQL data type is a numberic type. * * @param type one of the constants from <code>java.sql.Types</code> * @return <code>true</code> if the given type is <code>NUMERIC</code>,' * <code>DECIMAL</code>, <code>BIT</code>, <code>TINYINT</code>, * <code>SMALLINT</code>, <code>INTEGER</code>, <code>BIGINT</code>, * <code>REAL</code>, <code>DOUBLE</code>, or <code>FLOAT</code>; * <code>false</code> otherwise *//* w w w . j a v a 2 s .c o m*/ private boolean isNumeric(int type) { switch (type) { case java.sql.Types.NUMERIC: case java.sql.Types.DECIMAL: case java.sql.Types.BIT: case java.sql.Types.TINYINT: case java.sql.Types.SMALLINT: case java.sql.Types.INTEGER: case java.sql.Types.BIGINT: case java.sql.Types.REAL: case java.sql.Types.DOUBLE: case java.sql.Types.FLOAT: return true; default: return false; } }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Converts the given <code>Object</code> in the Java programming language * to the standard mapping for the specified SQL target data type. * The conversion must be to a string or numeric type, but there are no * restrictions on the type to be converted. If the source type and target * type are the same, the given object is simply returned. * * @param srcObj the <code>Object</code> in the Java programming language * that is to be converted to the target type * @param srcType the data type that is the standard mapping in SQL of the * object to be converted; must be one of the constants in * <code>java.sql.Types</code> * @param trgType the SQL data type to which to convert the given object; * must be one of the following constants in * <code>java.sql.Types</code>: <code>NUMERIC</code>, * <code>DECIMAL</code>, <code>BIT</code>, <code>TINYINT</code>, * <code>SMALLINT</code>, <code>INTEGER</code>, <code>BIGINT</code>, * <code>REAL</code>, <code>DOUBLE</code>, <code>FLOAT</code>, * <code>VARCHAR</code>, <code>LONGVARCHAR</code>, or <code>CHAR</code> * @return an <code>Object</code> value.that is * the standard object mapping for the target SQL type * @throws SQLException if the given target type is not one of the string or * numeric types in <code>java.sql.Types</code> *//*from w ww .j av a 2 s . co m*/ private Object convertNumeric(Object srcObj, int srcType, int trgType) throws SQLException { if (srcType == trgType) { return srcObj; } if (isNumeric(trgType) == false && isString(trgType) == false) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString() + trgType); } try { switch (trgType) { case java.sql.Types.BIT: Integer i = new Integer(srcObj.toString().trim()); return i.equals(new Integer((int) 0)) ? new Boolean(false) : new Boolean(true); case java.sql.Types.TINYINT: return new Byte(srcObj.toString().trim()); case java.sql.Types.SMALLINT: return new Short(srcObj.toString().trim()); case java.sql.Types.INTEGER: return new Integer(srcObj.toString().trim()); case java.sql.Types.BIGINT: return new Long(srcObj.toString().trim()); case java.sql.Types.NUMERIC: case java.sql.Types.DECIMAL: return new BigDecimal(srcObj.toString().trim()); case java.sql.Types.REAL: case java.sql.Types.FLOAT: return new Float(srcObj.toString().trim()); case java.sql.Types.DOUBLE: return new Double(srcObj.toString().trim()); case java.sql.Types.CHAR: case java.sql.Types.VARCHAR: case java.sql.Types.LONGVARCHAR: return new String(srcObj.toString()); default: throw new SQLException( resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString() + trgType); } } catch (NumberFormatException ex) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString() + trgType); } }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Sets the designated column in either the current row or the insert * row of this <code>CachedRowSetImpl</code> object with the given * <code>double</code> value. * * This method updates a column value in either the current row or * the insert row of this rowset, but it does not update the * database. If the cursor is on a row in the rowset, the * method {@link #updateRow} must be called to update the database. * If the cursor is on the insert row, the method {@link #insertRow} * must be called, which will insert the new row into both this rowset * and the database. Both of these methods must be called before the * cursor moves to another row./*from w w w . ja v a2 s. c o m*/ * * @param columnIndex the first column is <code>1</code>, the second * is <code>2</code>, and so on; must be <code>1</code> or larger * and equal to or less than the number of columns in this rowset * @param x the new column value * @throws SQLException if (1) the given column index is out of bounds, * (2) the cursor is not on one of this rowset's rows or its * insert row, or (3) this rowset is * <code>ResultSet.CONCUR_READ_ONLY</code> */ public void updateDouble(int columnIndex, double x) throws SQLException { // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); Object obj = convertNumeric(new Double(x), java.sql.Types.DOUBLE, RowSetMD.getColumnType(columnIndex)); getCurrentRow().setColumnObject(columnIndex, obj); }