quartz的job在jboss不能正常运行

发布于 2021-11-22 08:15:02 字数 6633 浏览 874 评论 1

 public class DataTransferSchedule extends AcsBasicDAO implements Job {

	public DataTransferSchedule(){}
	public void execute(JobExecutionContext context)
        throws JobExecutionException {
    	
		if ("1".equals(com.hitrust.visa3d.ias.basic.InitServlet.isLogDebug)) {
			ResultSet rs = null;
			PreparedStatement stmt = null;
			Statement statement = null;
			
			Connection connection = com.hitrust.visa3d.ias.util.ServiceLocator.getInstance()
                    .getHDataConnection();
			try {
				connection.setAutoCommit(false);
				statement = connection.createStatement();
				String sql = "";
				for(int i=0;i<tables.length;i++){
					sql = "DELETE FROM "+tables[i];
					statement.addBatch(sql);
				}
				statement.executeBatch();
				connection.commit();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				try {
					connection.rollback();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			} finally {
				closeResultSet(rs);
				closeStatement(stmt);
				if(connection!=null){
					try {
						connection.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			
			HashMap<String, String> coloumns = new HashMap<String, String>();
			getDBConnection();
			try {
				for(int i=0;i<tables.length;i++){
					closeResultSet(rs);
					closeStatement(stmt);
					String sql = "SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME='"+tables[i]+"'";
					stmt = dbConnection.prepareStatement(sql);
					rs = stmt.executeQuery();
					String columsString = "";
					while (rs.next()) {
						columsString += rs.getString("COLUMN_NAME")+",";
					}
					
					coloumns.put(tables[i].toLowerCase(), columsString.substring(0, columsString.length()-1));
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				closeResultSet(rs);
				closeStatement(stmt);
				closeConnection();
			}
			

			ArrayList<String> sqls = createInsertSql(coloumns);
			ArrayList<String> insertsqls = new ArrayList<String>();
			getDBConnection();
			try {
				for(int i=0;i<sqls.size();i++){
					closeResultSet(rs);
					closeStatement(stmt);
					stmt = dbConnection.prepareStatement(sqls.get(i));
					rs = stmt.executeQuery();
					while (rs.next()) {
						insertsqls.add(rs.getString(1));
					}
				}
				
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally {
				closeResultSet(rs);
				closeStatement(stmt);
				closeConnection();
			}
			
			if(insertsqls!=null && insertsqls.size()>0){

				Connection conn = com.hitrust.visa3d.ias.util.ServiceLocator.getInstance()
	                    .getHDataConnection();
				try {
					conn.setAutoCommit(false);
					statement = conn.createStatement();
					for(int i=0;i<insertsqls.size();i++){
						statement.addBatch(insertsqls.get(i));
						logger.debug(insertsqls.get(i));
					}
					statement.executeBatch();
					conn.commit();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					try {
						conn.rollback();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					e.printStackTrace();
				} finally {
					if(statement!=null){
						try {
							statement.close();
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					if(conn!=null){
						try {
							conn.close();
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
			}else{
				logger.debug("無符合條件的數據");
			}
			
			
		}

	}

	
	public static ArrayList<String> createInsertSql(HashMap<String, String> map){
		ArrayList<String> sqls = new ArrayList<String>();
		Iterator<?> it = map.entrySet().iterator();
		while (it.hasNext()) {
			String sqlString = "SELECT DISTINCT 'INSERT INTO ";
			@SuppressWarnings("unchecked")
			Map.Entry<String, String> entry = (Map.Entry<String, String>) it
					.next();
			String columnsString = entry.getValue();
			String tablenameString = entry.getKey();
			sqlString += tablenameString+" ("+columnsString+") VALUES (' ";
			String[] columnStrings = columnsString.split(",");
			
			if(tablenameString.toUpperCase().equals("T_ENROLLMENTSETUP_TMP")){
				for(int i=0;i<columnStrings.length;i++){
					if(columnStrings[i].toUpperCase().equals("BANKLOGO")){
						
						sqlString = sqlString.replace("BANKLOGO,", "");
					}else{
						sqlString += "|| '''' || "+columnStrings[i].toUpperCase()+" ||'''' || ','";
					}
				}
			}else{
				for(int i=0;i<columnStrings.length;i++){
					sqlString += "|| '''' || "+columnStrings[i].toUpperCase()+" ||'''' || ','";
				}
			}
			sqlString = sqlString.substring(0, sqlString.length()-3);
			sqlString += " ')' FROM "+tablenameString.toUpperCase();
			if(tablenameString.equals("t_authtransactionmessage")){
				sqlString += " WHERE to_char(AUTHTIME,'yyyy-mm-dd')<=to_char(add_months(sysdate,-1),'yyyy-mm-dd')";
			}
			else if(tablenameString.equals("t_authpass")){
				sqlString += " WHERE to_char(AGENT_DATE,'yyyy-mm-dd')<=to_char(add_months(sysdate,-1),'yyyy-mm-dd')";
			}
			else{
				sqlString += " WHERE to_char(to_date(AGENT_DATE,'yyyy-MM-dd hh24:mi:ss'),'yyyy-mm-dd')<=to_char(add_months(sysdate,-1),'yyyy-mm-dd')";
			}
			logger.debug("查詢語句:"+sqlString);
			sqls.add(sqlString);
		}
		return sqls;
	}
}


这一个job,在tomcat下正常使用,换到jboss下就完蛋了

16:40:00,062 ERROR [org.quartz.core.ErrorLogger] (TestScheduler_QuartzSchedulerT
hread) An error occured instantiating job to be executed. job= 'CommissionCharge
.CommissionChargeSchedule': org.quartz.SchedulerException: Problem instantiating
 class 'com.hitrust.visa3d.ias.system.reportForm.CommissionChargeSchedule' [See
nested exception: com.hitrust.visa3d.ias.system.dao.BasicDAOException: NamingExc
eption while looking up DataSource Connection :
java:comp/env/jdbc/acs]
        at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:52) [e
nrolllistener.jar:]
        at org.quartz.core.JobRunShell.initialize(JobRunShell.java:133) [enrolll
istener.jar:]
        at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:
353) [enrolllistener.jar:]



不明白为什么会报这种错误

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2021-11-23 02:06:13

环境不一样吧,可能有些配置或者jar需要改变,这个文档一般会有说明

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文