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

com.j2mvc.framework.dao.callback.MutilCreator Maven / Gradle / Ivy

Go to download

强烈建议使用J2mvc 2.1以后的版本。 version 2.1.01 1.更换JSON依赖包. version 2.1.02 1.移除com.j2mvc.StringUtils.getUtf8()方法调用. 更改为getCharset() version 2.1.03 1.更新JNDI连接设置 version 2.1.04 1.修改works.xml配置url-pkg-prefixes改为pkg

There is a newer version: 2.1.12
Show newest version
package com.j2mvc.framework.dao.callback;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import org.apache.log4j.Logger;
import com.j2mvc.framework.Session;
import com.j2mvc.framework.dao.DataSourceJndi;

/**
 * 创建预编译语句
 * @author 杨朔
 * 2014年3月28日 创建
 */
public class MutilCreator{
	Logger log = Logger.getLogger(getClass().getName());

	private List sqls;
	private String dataSourceName;
		
	public MutilCreator(List sqls,String dataSourceName) {
		this.sqls = sqls;
		this.dataSourceName = dataSourceName;
	}
	public int[] execute(){
		int[] num = null;
		Connection con = null;
		if(dataSourceName!=null && !dataSourceName.equals("")){
			con = DataSourceJndi.getConnection(dataSourceName);
		}
		if(con == null)
			con = DataSourceJndi.getConnection();
		try {
			Statement stmt = con.createStatement();
			con.setAutoCommit(false);
			for(String sql : sqls){
				if(Session.sqlLog)
					log.info(sql);
				stmt.addBatch(sql);
			}
			num = stmt.executeBatch();
			stmt.executeBatch();  
			con.commit();
			con.setAutoCommit(true);
			stmt.close();
			con.close();
		} catch (Exception ex) {
			try {
				con.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			ex.getMessage();
		}finally{
			if (con != null)
				try {
					con.close();
				} catch (SQLException e) {
					log.error(e.getMessage()); 
				}
   		}
		return num;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy