All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.icymint.libra.jdbc.param.DefaultParameter Maven / Gradle / Ivy

package me.icymint.libra.jdbc.param;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;

import me.icymint.libra.jdbc.JdbcAccessException;

/**
 * 处理通用的参数设置。
 * 
 * @author Daniel Yu
 * @since 2013-3-13
 * 
 */
public class DefaultParameter implements Parameter {
	private final int[] types;

	public DefaultParameter() {
		this(new int[] {});
	}

	public DefaultParameter(int[] types) {
		this.types = types;
	}

	@Override
	public void handle(PreparedStatement u, Object[] p)
			throws JdbcAccessException {
		try {
			if (types.length != p.length)
				throw new JdbcAccessException("参数个数不匹配!");
			for (int i = 0; i < p.length; i++) {
				Object o = p[i];
				if (o == null)
					u.setNull(i + 1, types[i]);
				else
					u.setObject(i + 1, p[i], types[i]);
			}
		} catch (SQLException e) {
			throw new JdbcAccessException("参数设置:" + Arrays.toString(p), e);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy