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

📄 monetpreparedstatement.java

📁 这个是内存数据库的客户端
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			}		} else if (x instanceof Boolean) {			boolean val = ((Boolean)x).booleanValue();			switch (targetSqlType) {				case Types.TINYINT:					setByte(parameterIndex, (byte)(val ? 1 : 0));				break;				case Types.SMALLINT:					setShort(parameterIndex, (short)(val ? 1 : 0));				break;				case Types.INTEGER:					setInt(parameterIndex, (int)(val ? 1 : 0));				break;				case Types.BIGINT:					setLong(parameterIndex, (long)(val ? 1 : 0));				break;				case Types.REAL:					setFloat(parameterIndex, (float)(val ? 1.0 : 0.0));				break;				case Types.FLOAT:				case Types.DOUBLE:					setDouble(parameterIndex, (double)(val ? 1.0 : 0.0));				break;				case Types.DECIMAL:				case Types.NUMERIC:				{					BigDecimal dec;					try {						dec = new BigDecimal(val ? 1.0 : 0.0);					} catch (NumberFormatException e) {						throw new SQLException("Internal error: unable to create template BigDecimal: " + e.getMessage());					}					setBigDecimal(parameterIndex, dec);				} break;				case Types.BIT:				case Types.BOOLEAN:					setBoolean(parameterIndex, val);				break;				case Types.CHAR:				case Types.VARCHAR:				case Types.LONGVARCHAR:					setString(parameterIndex, "" + val);				break;				default:					throw new SQLException("Conversion not allowed");			}		} else if (x instanceof byte[]) {			switch (targetSqlType) {				case Types.BINARY:				case Types.VARBINARY:				case Types.LONGVARBINARY:					setBytes(parameterIndex, (byte[])x);				break;				default:					throw new SQLException("Conversion not allowed");			}		} else if (x instanceof java.sql.Date ||				x instanceof Timestamp ||				x instanceof Time)		{			switch (targetSqlType) {				case Types.CHAR:				case Types.VARCHAR:				case Types.LONGVARCHAR:					setString(parameterIndex, x.toString());				break;				case Types.DATE:					if (x instanceof Time) {						throw new SQLException("Conversion not allowed");					} else if (x instanceof java.sql.Date) {						setDate(parameterIndex, (java.sql.Date)x);					} else if (x instanceof Timestamp) {						setDate(parameterIndex, new java.sql.Date(((Timestamp)x).getTime()));					}				break;				case Types.TIME:					if (x instanceof Time) {						setTime(parameterIndex, (Time)x);					} else if (x instanceof java.sql.Date) {						throw new SQLException("Conversion not allowed");					} else if (x instanceof Timestamp) {						setTime(parameterIndex, new Time(((Timestamp)x).getTime()));					}				break;				case Types.TIMESTAMP:					if (x instanceof Time) {						throw new SQLException("Conversion not allowed");					} else if (x instanceof java.sql.Date) {						setTimestamp(parameterIndex, new Timestamp(((java.sql.Date)x).getTime()));					} else if (x instanceof Timestamp) {						setTimestamp(parameterIndex, (Timestamp)x);					}				break;				default:					throw new SQLException("Conversion not allowed");			}		} else if (x instanceof Array) {			setArray(parameterIndex, (Array)x);		} else if (x instanceof Blob) {			setBlob(parameterIndex, (Blob)x);		} else if (x instanceof Clob) {			setClob(parameterIndex, (Clob)x);		} else if (x instanceof Struct) {			// I have no idea how to do this...			throw new SQLException("Operation currently not supported!");		} else if (x instanceof Ref) {			setRef(parameterIndex, (Ref)x);		} else if (x instanceof java.net.URL) {			setURL(parameterIndex, (java.net.URL)x);		} else if (x instanceof SQLData) {			// do something with:			// ((SQLData)x).writeSQL( [java.sql.SQLOutput] );			// needs an SQLOutput stream... bit too far away from reality			throw new SQLException("Operation currently not supported!");		} else {	// java Class			throw new SQLException("Operation currently not supported!");		}	}	/**	 * Sets the designated parameter to the given REF(<structured-type>) value.	 * The driver converts this to an SQL REF value when it sends it to the	 * database.	 *	 * @param i the first parameter is 1, the second is 2, ...	 * @param x an SQL REF value	 * @throws SQLException if a database access error occurs	 */	public void setRef(int i, Ref x) throws SQLException {		throw new SQLException("Operation currently not supported!");	}	/**	 * Sets the designated parameter to the given Java short value. The driver	 * converts this to an SQL SMALLINT 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 setShort(int parameterIndex, short x) throws SQLException {		setValue(parameterIndex, "" + x);	}	/**	 * Sets the designated parameter to the given Java String value. The driver	 * converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the	 * argument's size relative to the driver's limits on VARCHAR values) 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 setString(int parameterIndex, String x) throws SQLException {		setValue(			parameterIndex,			"'" + x.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'") + "'"		);	}	/**	 * Sets the designated parameter to the given java.sql.Time value.	 * The driver converts this to an SQL TIME value when it sends it to	 * the database.	 *	 * @param index the first parameter is 1, the second is 2, ...	 * @param x the parameter value	 * @throws SQLException if a database access error occurs	 */	public void setTime(int index, Time x) throws SQLException {		if (index < 1 || index > size)			throw new SQLException("No such parameter with index: " + index);		setValue(index, monetdbType[index - 1] + " '" + x.toString() + "'");	}	/**	 * Sets the designated parameter to the given java.sql.Time value,	 * using the given Calendar object.  The driver uses the Calendar	 * object to construct an SQL TIME value, which the driver then	 * sends to the database.  With a Calendar object, the driver can	 * calculate the time taking into account a custom timezone.  If no	 * Calendar object is specified, the driver uses the default	 * timezone, which is that of the virtual machine running the	 * application.	 *	 * @param index the first parameter is 1, the second is 2, ...	 * @param x the parameter value	 * @param cal the Calendar object the driver will use to construct the time	 * @throws SQLException if a database access error occurs	 */	public void setTime(int index, Time x, Calendar cal)		throws SQLException	{		if (index < 1 || index > size)			throw new SQLException("No such parameter with index: " + index);		mTimeZ.setTimeZone(cal.getTimeZone());		String RFC822 = mTimeZ.format(x);		setValue(index, monetdbType[index - 1] + " '" +				RFC822.substring(0, 15) + ":" + RFC822.substring(15) + "'");	}	/**	 * Sets the designated parameter to the given java.sql.Timestamp	 * value.  The driver converts this to an SQL TIMESTAMP value when	 * it sends it to the database.	 *	 * @param index the first parameter is 1, the second is 2, ...	 * @param x the parameter value	 * @throws SQLException if a database access error occurs	 */	public void setTimestamp(int index, Timestamp x)		throws SQLException	{		if (index < 1 || index > size)			throw new SQLException("No such parameter with index: " + index);		setValue(index, monetdbType[index - 1] + " '" + x.toString() + "'");	}    /**	 * Sets the designated parameter to the given java.sql.Timestamp	 * value, using the given Calendar object.  The driver uses the	 * Calendar object to construct an SQL TIMESTAMP value, which the	 * driver then sends to the database.  With a Calendar object, the	 * driver can calculate the timestamp taking into account a custom	 * timezone.  If no Calendar object is specified, the driver uses the	 * default timezone, which is that of the virtual machine running	 * the application.	 *	 * @param index the first parameter is 1, the second is 2, ...	 * @param x the parameter value	 * @param cal the Calendar object the driver will use to construct the	 *            timestamp	 * @throws SQLException if a database access error occurs	 */	public void setTimestamp(int index, Timestamp x, Calendar cal)		throws SQLException	{		if (index < 1 || index > size)			throw new SQLException("No such parameter with index: " + index);		if (cal == null) cal = Calendar.getInstance();		mTimestampZ.setTimeZone(cal.getTimeZone());		String RFC822 = mTimestampZ.format(x);		setValue(index, monetdbType[index - 1] + " '" +				RFC822.substring(0, 26) + ":" + RFC822.substring(26) + "'");	}	/**	 * Sets the designated parameter to the given input stream, which will have	 * the specified number of bytes. A Unicode character has two bytes, with	 * the first byte being the high byte, and the second being the low byte.	 * When a very large Unicode value is input to a LONGVARCHAR parameter, it	 * may be more practical to send it via a java.io.InputStream object. The	 * data will be read from the stream as needed until end-of-file is	 * reached. The JDBC driver will do any necessary conversion from Unicode	 * to the database char format.	 * <br /><br />	 * Note: This stream object can either be a standard Java stream object or	 * your own subclass that implements the standard interface.	 *	 * @deprecated	 * @param parameterIndex the first parameter is 1, the second is 2, ...	 * @param x a java.io.InputStream object that contains the Unicode	 *          parameter value as two-byte Unicode characters	 * @param length the number of bytes in the stream	 * @throws SQLException if a database access error occurs	 */	public void setUnicodeStream(int parameterIndex, InputStream x, int length)		throws SQLException	{		throw new SQLException("Operation currently not supported!");	}	/**	 * Sets the designated parameter to the given java.net.URL value. The	 * driver converts this to an SQL DATALINK value when it sends it to the	 * database.	 *	 * @param parameterIndex the first parameter is 1, the second is 2, ...	 * @param x the java.net.URL object to be set	 * @throws SQLException if a database access error occurs	 */	public void setURL(int parameterIndex, URL x) throws SQLException {		throw new SQLException("Operation currently not supported!");	}	//== end methods interface PreparedStatement	/**	 * Sets the given index with the supplied value. If the given index is	 * out of bounds, and SQLException is thrown.  The given value should	 * never be null.	 *	 * @param index the parameter index	 * @param val the exact String representation to set	 * @throws SQLException if the given index is out of bounds	 */	void setValue(int index, String val) throws SQLException {		if (index < 1 || index > size)			throw new SQLException("No such parameter with index: " + index);		values[index - 1] = val;	}	/**	 * Transforms the prepare query into a simple SQL query by replacing	 * the ?'s with the given column contents.	 * Mind that the JDBC specs allow `reuse' of a value for a column over	 * multiple executes.	 *	 * @return the simple SQL string for the prepare query	 * @throws SQLException if not all columns are set	 */	private String transform() throws SQLException {		buf.delete(0, buf.length());		buf.append("exec ");		buf.append(id);		buf.append("(");		// check if all columns are set and do a replace		for (int i = 0; i < size; i++) {			if (i > 0) buf.append(", ");			if (values[i] == null) throw				new SQLException("Cannot execute, parameter " +  (i + 1) + " is missing.");			buf.append(values[i]);		}		buf.append(")");				return(buf.toString());	}}

⌨️ 快捷键说明

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