List of usage examples for java.sql Types INTEGER
int INTEGER
To view the source code for java.sql Types INTEGER.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER
.
From source file:com.enonic.vertical.engine.handlers.MenuHandler.java
private void updateMenu(User user, CopyContext copyContext, Document doc, boolean useOldKeys) throws VerticalUpdateException, VerticalSecurityException { Element root_elem = doc.getDocumentElement(); // get menu key: String tmp = root_elem.getAttribute("key"); SiteKey menuKey = new SiteKey(tmp); Connection con = null;/*from w w w.j a v a 2 s.c o m*/ PreparedStatement preparedStmt = null; try { con = getConnection(); // Update the main menu table: preparedStmt = con.prepareStatement(MENU_UPDATE); // firstpage: Element tmpElement = XMLTool.getElement(root_elem, "firstpage"); tmp = tmpElement.getAttribute("key"); if (tmp != null && tmp.length() > 0) { preparedStmt.setInt(1, Integer.parseInt(tmp)); } else { preparedStmt.setNull(1, Types.INTEGER); } // loginpage: tmpElement = XMLTool.getElement(root_elem, "loginpage"); tmp = tmpElement.getAttribute("key"); if (tmp != null && tmp.length() > 0) { preparedStmt.setInt(2, Integer.parseInt(tmp)); } else { preparedStmt.setNull(2, Types.INTEGER); } // errorpage: tmpElement = XMLTool.getElement(root_elem, "errorpage"); tmp = tmpElement.getAttribute("key"); if (tmp != null && tmp.length() > 0) { preparedStmt.setInt(3, Integer.parseInt(tmp)); } else { preparedStmt.setNull(3, Types.INTEGER); } // default pagetemplate: tmpElement = XMLTool.getElement(root_elem, "defaultpagetemplate"); if (tmpElement != null) { tmp = tmpElement.getAttribute("pagetemplatekey"); preparedStmt.setInt(4, Integer.parseInt(tmp)); } else { preparedStmt.setNull(4, Types.INTEGER); } SiteData siteData = new SiteData(); // DeviceClassResolver: tmpElement = XMLTool.getElement(root_elem, "deviceclassresolver"); if (tmpElement != null) { String deviceClassResolverUrl = tmpElement.getAttribute("key"); if (StringUtils.isNotEmpty(deviceClassResolverUrl)) { siteData.setDeviceClassResolver(new ResourceKey(deviceClassResolverUrl)); } } // default localization resource: tmpElement = XMLTool.getElement(root_elem, "defaultlocalizationresource"); if (tmpElement != null) { String defaultLocalizationResource = tmpElement.getAttribute("key"); if (StringUtils.isNotEmpty(defaultLocalizationResource)) { siteData.setDefaultLocalizationResource(new ResourceKey(defaultLocalizationResource)); } } // locale resolver: tmpElement = XMLTool.getElement(root_elem, "localeresolver"); if (tmpElement != null) { String localeResolver = tmpElement.getAttribute("key"); if (StringUtils.isNotEmpty(localeResolver)) { siteData.setLocaleResolver(new ResourceKey(localeResolver)); } } // Path to public home: String pathToPublicHome = root_elem.getAttribute("pathtopublichome"); if (StringUtils.isNotEmpty(pathToPublicHome)) { siteData.setPathToPublicResources(new ResourceKey(pathToPublicHome)); } // Path to home: String pathToHome = root_elem.getAttribute("pathtohome"); if (StringUtils.isNotEmpty(pathToHome)) { siteData.setPathToResources(new ResourceKey(pathToHome)); } tmpElement = XMLTool.getElement(root_elem, "menudata"); if (tmpElement != null) { parseAndAddMenudataToSiteData(tmpElement, siteData); } final byte[] xmldata = siteData.getAsBytes(); preparedStmt.setBinaryStream(5, new ByteArrayInputStream(xmldata), xmldata.length); // language key: preparedStmt.setInt(6, Integer.parseInt(root_elem.getAttribute("languagekey"))); Element detailsElement = XMLTool.getElement(root_elem, "details"); // Statistics URL: tmpElement = XMLTool.getElement(detailsElement, "statistics"); if (tmpElement != null) { String name = XMLTool.getElementText(tmpElement); if (name != null) { preparedStmt.setString(7, name); } else { preparedStmt.setNull(7, Types.VARCHAR); } } else { preparedStmt.setNull(7, Types.VARCHAR); } // Run As User: String runAsUserKey = root_elem.getAttribute("runas"); if (StringUtils.isNotEmpty(runAsUserKey)) { preparedStmt.setString(8, runAsUserKey); } else { preparedStmt.setNull(8, Types.VARCHAR); } // menu key: preparedStmt.setInt(9, menuKey.toInt()); preparedStmt.executeUpdate(); preparedStmt.close(); preparedStmt = null; // Update the individual menuitems (recursivly): try { Element[] elems = XMLTool.getElements(XMLTool.getElement(root_elem, "menuitems")); for (int i = 0; i < elems.length; i++) { String curDeleted = elems[i].getAttribute("deleted"); if (!"deleted".equals(curDeleted)) { String curKey = elems[i].getAttribute("key"); if (curKey == null || curKey.length() == 0 || !useOldKeys) { createMenuItem(user, copyContext, elems[i], menuKey, i, null, useOldKeys); } else { updateMenuItem(user, elems[i], menuKey, i, null, true); } } } } catch (VerticalCreateException vce) { VerticalEngineLogger.errorUpdate(this.getClass(), 2, "Failed to create new menuitem: %t", vce); } // get all deleted menuitems: String xpath = "//menuitem[@deleted = 'deleted']"; try { // Search for the xpath: NodeList list = XMLTool.selectNodes(doc.getDocumentElement(), xpath); // Loop through the results. for (int i = 0; i < list.getLength(); i++) { Element n = (Element) list.item(i); tmp = n.getAttribute("key"); removeMenuItem(user, Integer.parseInt(tmp)); } } catch (VerticalRemoveException vre) { VerticalEngineLogger.errorUpdate(this.getClass(), 3, "Failed to remove menuitem: %t", vre); } } catch (SQLException sqle) { VerticalEngineLogger.errorUpdate(this.getClass(), 5, "A database error occurred: %t", sqle); } finally { close(preparedStmt); close(con); } }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbMySql.CFGenKbMySqlGelIteratorTable.java
public void deleteGelIteratorByNextIdx(CFGenKbAuthorization Authorization, long argTenantId, long argCartridgeId, Integer argNextId) { final String S_ProcName = "deleteGelIteratorByNextIdx"; ResultSet resultSet = null;/*from w w w .ja v a2 s . c o m*/ try { Connection cnx = schema.getCnx(); String sql = "call " + schema.getLowerSchemaDbName() + ".sp_delete_geliter_by_nextidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtDeleteByNextIdx == null) { stmtDeleteByNextIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByNextIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByNextIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByNextIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByNextIdx.setLong(argIdx++, argTenantId); stmtDeleteByNextIdx.setLong(argIdx++, argCartridgeId); if (argNextId != null) { stmtDeleteByNextIdx.setInt(argIdx++, argNextId.intValue()); } else { stmtDeleteByNextIdx.setNull(argIdx++, java.sql.Types.INTEGER); } stmtDeleteByNextIdx.executeUpdate(); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:com.enonic.vertical.engine.handlers.MenuHandler.java
private void updateMenuItemData(User user, Element menuItemElem, int type, MenuItemKey parent, int order) throws VerticalUpdateException { String tmp;/* w ww . j a va 2 s . co m*/ boolean modified = "modified".equals(menuItemElem.getAttribute("modified")); Connection con = null; PreparedStatement preparedStmt = null; try { con = getConnection(); // update the main table: int psCounter = 1; if (modified) { preparedStmt = con.prepareStatement(MENU_ITEM_UPDATE); } else { preparedStmt = con.prepareStatement(MENU_ITEM_UPDATE_NO_DATA); } //} // name Element tmp_elem = XMLTool.getElement(menuItemElem, ELEMENT_NAME_MENUITEM_NAME); String name = XMLTool.getElementText(tmp_elem); validateMenuItemName(name); StringReader sreader = new StringReader(name); preparedStmt.setCharacterStream(psCounter++, sreader, name.length()); if (parent != null) { preparedStmt.setInt(psCounter++, parent.toInt()); } else { preparedStmt.setNull(psCounter++, Types.INTEGER); } // order preparedStmt.setInt(psCounter++, order); Element dataElem; if (modified) { dataElem = XMLTool.getElement(menuItemElem, "data"); // parameters tmp_elem = XMLTool.getElement(menuItemElem, "parameters"); if (tmp_elem != null) { dataElem.appendChild(tmp_elem); } } else { dataElem = null; } // alternative name: tmp_elem = XMLTool.getElement(menuItemElem, ELEMENT_NAME_MENU_NAME); if (tmp_elem != null) { tmp = XMLTool.getElementText(tmp_elem); preparedStmt.setString(psCounter++, tmp); } else { preparedStmt.setNull(psCounter++, Types.VARCHAR); } // visibility: tmp = menuItemElem.getAttribute("visible"); if ("no".equals(tmp)) { preparedStmt.setInt(psCounter++, 1); } else { preparedStmt.setInt(psCounter++, 0); } // description: tmp_elem = XMLTool.getElement(menuItemElem, "description"); String data = XMLTool.getElementText(tmp_elem); if (data == null) { data = ""; } StringReader reader = new StringReader(data); preparedStmt.setCharacterStream(psCounter++, reader, data.length()); // keywords tmp_elem = XMLTool.getElement(menuItemElem, "keywords"); String keywords = XMLTool.getElementText(tmp_elem); if (keywords == null || keywords.length() == 0) { preparedStmt.setNull(psCounter++, Types.VARCHAR); } else { StringReader keywordReader = new StringReader(keywords); preparedStmt.setCharacterStream(psCounter++, keywordReader, keywords.length()); } // language String lanKey = menuItemElem.getAttribute("languagekey"); if ((lanKey != null) && (lanKey.length() > 0)) { preparedStmt.setInt(psCounter++, Integer.parseInt(lanKey)); } else { preparedStmt.setNull(psCounter++, Types.INTEGER); } // get menuitem key: tmp = menuItemElem.getAttribute("key"); int key = Integer.parseInt(tmp); // owner String ownerKey = menuItemElem.getAttribute("owner"); // modifier String modifierKey = menuItemElem.getAttribute("modifier"); if (modified && type == 4) { //byte[] document = null; Element docElem = XMLTool.getElement(menuItemElem, "document"); dataElem.appendChild(docElem); } preparedStmt.setString(psCounter++, ownerKey); preparedStmt.setString(psCounter++, modifierKey); RunAsType runAs = RunAsType.INHERIT; String runAsStr = menuItemElem.getAttribute("runAs"); if (StringUtils.isNotEmpty(runAsStr)) { runAs = RunAsType.valueOf(runAsStr); } preparedStmt.setInt(psCounter++, runAs.getKey()); // displayname: tmp_elem = XMLTool.getElement(menuItemElem, ELEMENT_NAME_DISPLAY_NAME); if (tmp_elem == null) { throw new IllegalArgumentException("Displayname must be set"); } else { tmp = XMLTool.getElementText(tmp_elem); preparedStmt.setString(psCounter++, tmp); } // data if (modified) { Document dataDoc = XMLTool.createDocument(); dataDoc.appendChild(dataDoc.importNode(dataElem, true)); byte[] bytes = XMLTool.documentToBytes(dataDoc, "UTF-8"); preparedStmt.setBinaryStream(psCounter++, new ByteArrayInputStream(bytes), bytes.length); } preparedStmt.setInt(psCounter, key); preparedStmt.executeUpdate(); if (multicaster.hasListeners()) { int menuKey = getMenuKeyByMenuItem(key); MenuHandlerEvent e = new MenuHandlerEvent(user, menuKey, key, name, this); multicaster.updatedMenuItem(e); } } catch (SQLException sqle) { VerticalEngineLogger.errorUpdate(this.getClass(), 20, "SQL error while updating menuitem data.", sqle); } finally { close(preparedStmt); close(con); } }
From source file:com.mirth.connect.donkey.server.data.jdbc.JdbcDao.java
private static String sqlTypeToString(int sqlType) { switch (sqlType) { case Types.ARRAY: return "ARRAY"; case Types.BIGINT: return "BIGINT"; case Types.BINARY: return "BINARY"; case Types.BIT: return "BIT"; case Types.BLOB: return "BLOB"; case Types.BOOLEAN: return "BOOLEAN"; case Types.CHAR: return "CHAR"; case Types.CLOB: return "CLOB"; case Types.DATALINK: return "DATALINK"; case Types.DATE: return "DATE"; case Types.DECIMAL: return "DECIMAL"; case Types.DISTINCT: return "DISTINCT"; case Types.DOUBLE: return "DOUBLE"; case Types.FLOAT: return "FLOAT"; case Types.INTEGER: return "INTEGER"; case Types.JAVA_OBJECT: return "JAVA_OBJECT"; case Types.LONGNVARCHAR: return "LONGNVARCHAR"; case Types.LONGVARBINARY: return "LONGVARBINARY"; case Types.LONGVARCHAR: return "LONGVARCHAR"; case Types.NCHAR: return "NCHAR"; case Types.NCLOB: return "NCLOB"; case Types.NULL: return "NULL"; case Types.NUMERIC: return "NUMERIC"; case Types.NVARCHAR: return "NVARCHAR"; case Types.OTHER: return "OTHER"; case Types.REAL: return "REAL"; case Types.REF: return "REF"; case Types.ROWID: return "ROWID"; case Types.SMALLINT: return "SMALLINT"; case Types.SQLXML: return "SQLXML"; case Types.STRUCT: return "STRUCT"; case Types.TIME: return "TIME"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.TINYINT: return "TINYINT"; case Types.VARBINARY: return "VARBINARY"; case Types.VARCHAR: return "VARCHAR"; default://from w w w . j a v a 2s.c om return "UNKNOWN"; } }
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 w w .j av a2 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: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 ww . j a v a 2s . c om*/ 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 ww .j ava 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> */// w w w.j av a 2s . c o 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>int</code> value./*from w w w . j a v a2 s .com*/ * <P> * This method updates a column value in 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. * * @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 updateInt(int columnIndex, int x) throws SQLException { // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); Object obj = convertNumeric(new Integer(x), java.sql.Types.INTEGER, RowSetMD.getColumnType(columnIndex)); getCurrentRow().setColumnObject(columnIndex, obj); }