⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monetpreparedstatement.java

📁 这个是内存数据库的客户端
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		setValue(parameterIndex, "" + x);	}	/**	 * Sets the designated parameter to the given Java int value. The driver	 * converts this to an SQL INTEGER value when it sends it to the database.	 *	 * @param parameterIndex the first parameter is 1, the second is 2, ...	 * @param x the parameter value	 * @throws SQLException if a database access error occurs	 */	public void setInt(int parameterIndex, int x) throws SQLException {		setValue(parameterIndex, "" + x);	}	/**	 * Sets the designated parameter to the given Java long value. The driver	 * converts this to an SQL BIGINT value when it sends it to the database.	 *	 * @param parameterIndex the first parameter is 1, the second is 2, ...	 * @param x the parameter value	 * @throws SQLException if a database access error occurs	 */	public void setLong(int parameterIndex, long x) throws SQLException {		setValue(parameterIndex, "" + x);	}	/**	 * Sets the designated parameter to SQL NULL.	 * <br /><br />	 * Note: You must specify the parameter's SQL type.	 *	 * @param parameterIndex the first parameter is 1, the second is 2, ...	 * @param sqlType the SQL type code defined in java.sql.Types	 * @throws SQLException if a database access error occurs	 */	public void setNull(int parameterIndex, int sqlType) throws SQLException {		// we discard the given type here, the backend converts the		// value NULL to whatever it needs for the column		setValue(parameterIndex, "NULL");	}	/**	 * Sets the designated parameter to SQL NULL. This version of the method	 * setNull should be used for user-defined types and REF type parameters.	 * Examples of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT,	 * and named array types.	 * <br /><br />	 * Note: To be portable, applications must give the SQL type code and the	 * fully-qualified SQL type name when specifying a NULL user-defined or REF	 * parameter. In the case of a user-defined type the name is the type name	 * of the parameter itself. For a REF parameter, the name is the type name	 * of the referenced type. If a JDBC driver does not need the type code or	 * type name information, it may ignore it. Although it is intended for	 * user-defined and Ref parameters, this method may be used to set a null	 * parameter of any JDBC type. If the parameter does not have a	 * user-defined or REF type, the given typeName is ignored.	 *	 * @param paramIndex the first parameter is 1, the second is 2, ...	 * @param sqlType a value from java.sql.Types	 * @param typeName the fully-qualified name of an SQL user-defined type;	 *                 ignored if the parameter is not a user-defined type or	 *                 REF	 * @throws SQLException if a database access error occurs	 */	public void setNull(int paramIndex, int sqlType, String typeName)		throws SQLException	{		throw new SQLException("Operation currently not supported!");	}	/**	 * Sets the value of the designated parameter using the given	 * object.  The second parameter must be of type Object; therefore,	 * the java.lang equivalent objects should be used for built-in	 * types.	 * <br /><br />	 * The JDBC specification specifies a standard mapping from Java	 * Object types to SQL types. The given argument will be converted	 * to the corresponding SQL type before being sent to the database.	 * <br /><br />	 * Note that this method may be used to pass datatabase-specific	 * abstract data types, by using a driver-specific Java type. If the	 * object is of a class implementing the interface SQLData, the JDBC	 * driver should call the method SQLData.writeSQL to write it to the	 * SQL data stream. If, on the other hand, the object is of a class	 * implementing Ref, Blob, Clob, Struct, or Array, the driver should	 * pass it to the database as a value of the corresponding SQL type.	 * <br /><br />	 * This method throws an exception if there is an ambiguity, for	 * example, if the object is of a class implementing more than one	 * of the interfaces named above.	 *	 * @param index the first parameter is 1, the second is 2, ...	 * @param x the object containing the input parameter value	 * @throws SQLException if a database access error occurs or the type of	 *                      the given object is ambiguous	 */	public void setObject(int index, Object x) throws SQLException {		if (index < 1 || index > size)			throw new SQLException("No such parameter with index: " + index);		setObject(index, x, javaType[index - 1]);	}	/**	 * Sets the value of the designated parameter with the given object. This	 * method is like the method setObject blow, except that it assumes a scale	 * of zero.	 *	 * @param parameterIndex the first parameter is 1, the second is 2, ...	 * @param x the object containing the input parameter value	 * @param targetSqlType the SQL type (as defined in java.sql.Types) to be	 *                      sent to the database	 * @throws SQLException if a database access error occurs	 */	public void setObject(int parameterIndex, Object x, int targetSqlType)		throws SQLException	{		setObject(parameterIndex, x, targetSqlType, 0);	}	/**	 * Sets the value of the designated parameter with the given object. The	 * second argument must be an object type; for integral values, the	 * java.lang equivalent objects should be used.	 * <br /><br />	 * The given Java object will be converted to the given targetSqlType	 * before being sent to the database. If the object has a custom mapping	 * (is of a class implementing the interface SQLData), the JDBC driver	 * should call the method SQLData.writeSQL to write it to the SQL data	 * stream. If, on the other hand, the object is of a class implementing	 * Ref, Blob, Clob, Struct, or Array, the driver should pass it to the	 * database as a value of the corresponding SQL type.	 * <br /><br />	 * Note that this method may be used to pass database-specific abstract	 * data types.	 * <br /><br />	 * To meet the requirements of this interface, the Java object is	 * converted in the driver, instead of using a SQL CAST construct.	 *	 * @param parameterIndex the first parameter is 1, the second is 2, ...	 * @param x the object containing the input parameter value	 * @param targetSqlType the SQL type (as defined in java.sql.Types) to	 *                      be sent to the database. The scale argument may	 *                      further qualify this type.	 * @param scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,	 *              this is the number of digits after the decimal point. For	 *              all other types, this value will be ignored.	 * @throws SQLException if a database access error occurs	 * @see Types	 */	public void setObject(		int parameterIndex,		Object x,		int targetSqlType,		int scale)		throws SQLException	{		// this is according to table B-5		if (x instanceof String) {			switch (targetSqlType) {				case Types.TINYINT:				case Types.SMALLINT:				case Types.INTEGER:				{					int val;					try {						val = Integer.parseInt((String)x);					} catch (NumberFormatException e) {						val = 0;					}					setInt(parameterIndex, val);				} break;				case Types.BIGINT:				{					long val;					try {						val = Long.parseLong((String)x);					} catch (NumberFormatException e) {						val = 0;					}					setLong(parameterIndex, val);				} break;				case Types.REAL:				{					float val;					try {						val = Float.parseFloat((String)x);					} catch (NumberFormatException e) {						val = 0;					}					setFloat(parameterIndex, val);				} break;				case Types.FLOAT:				case Types.DOUBLE:				{					double val;					try {						val = Double.parseDouble((String)x);					} catch (NumberFormatException e) {						val = 0;					}					setDouble(parameterIndex, val);				} break;				case Types.DECIMAL:				case Types.NUMERIC:				{					BigDecimal val;					try {						val = new BigDecimal((String)x);					} catch (NumberFormatException e) {						try {							val = new BigDecimal(0.0);						} catch (NumberFormatException ex) {							throw new SQLException("Internal error: unable to create template BigDecimal: " + ex.getMessage());						}					}					val = val.setScale(scale, BigDecimal.ROUND_HALF_UP);					setBigDecimal(parameterIndex, val);				} break;				case Types.BIT:				case Types.BOOLEAN:					setBoolean(parameterIndex, (Boolean.valueOf((String)x)).booleanValue());				break;				case Types.CHAR:				case Types.VARCHAR:				case Types.LONGVARCHAR:					setString(parameterIndex, (String)x);				break;				case Types.BINARY:				case Types.VARBINARY:				case Types.LONGVARBINARY:					setBytes(parameterIndex, ((String)x).getBytes());				break;				case Types.DATE:				{					java.sql.Date val;					try {						val = java.sql.Date.valueOf((String)x);					} catch (IllegalArgumentException e) {						val = new java.sql.Date(0L);					}					setDate(parameterIndex, val);				} break;				case Types.TIME:				{					Time val;					try {						val = Time.valueOf((String)x);					} catch (IllegalArgumentException e) {						val = new Time(0L);					}					setTime(parameterIndex, val);				} break;				case Types.TIMESTAMP:				{					Timestamp val;					try {						val = Timestamp.valueOf((String)x);					} catch (IllegalArgumentException e) {						val = new Timestamp(0L);					}					setTimestamp(parameterIndex, val);				} break;				default:					throw new SQLException("Conversion not allowed");			}		} else if (x instanceof Number) {			Number num = (Number)x;			switch (targetSqlType) {				case Types.TINYINT:					setByte(parameterIndex, num.byteValue());				break;				case Types.SMALLINT:					setShort(parameterIndex, num.shortValue());				break;				case Types.INTEGER:					setInt(parameterIndex, num.intValue());				break;				case Types.BIGINT:					if (x instanceof BigDecimal) {						setLong(parameterIndex, ((BigDecimal)x).setScale(scale, BigDecimal.ROUND_HALF_UP).longValue());					} else {						setLong(parameterIndex, num.longValue());					}				break;				case Types.REAL:					setFloat(parameterIndex, num.floatValue());				break;				case Types.FLOAT:				case Types.DOUBLE:					setDouble(parameterIndex, num.doubleValue());				break;				case Types.DECIMAL:				case Types.NUMERIC:					if (x instanceof BigDecimal) {						setBigDecimal(parameterIndex, (BigDecimal)x);					} else if (x instanceof BigInteger) {						BigDecimal val;						try {							val = new BigDecimal((BigInteger)x, scale);						} catch (NumberFormatException e) {							try {								val = new BigDecimal(0.0);							} catch (NumberFormatException ex) {								throw new SQLException("Internal error: unable to create template BigDecimal: " + ex.getMessage());							}						}						setBigDecimal(parameterIndex, val);					} else {						BigDecimal val;						try {							val = new BigDecimal(num.doubleValue());						} catch (NumberFormatException e) {							try {								val = new BigDecimal(0.0);							} catch (NumberFormatException ex) {								throw new SQLException("Internal error: unable to create template BigDecimal: " + ex.getMessage());							}						}						setBigDecimal(parameterIndex, val);					}				break;				case Types.BIT:				case Types.BOOLEAN:					if (num.doubleValue() != 0.0) {						setBoolean(parameterIndex, true);					} else {						setBoolean(parameterIndex, false);					}				break;				case Types.CHAR:				case Types.VARCHAR:				case Types.LONGVARCHAR:					setString(parameterIndex, x.toString());				break;				default:					throw new SQLException("Conversion not allowed");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -