iT邦幫忙

0

Java try-catch 問題

我想捕捉 java.sql.SQLDataException: ORA-01438: 值大於此資料欄所允許的指定精確度
這個Exception
預想是當出現這個EXCEPTION時 print "我想印出這行"
但結果卻是印出*****
以下是簡略過後的程式碼

public String createOrder(String orderno) {
		String msg =null;

		try {

			testDao.createOrder(orderno);
			
		} catch (SQLException se) {

			logger.error(se);
			System.out.println("我想印出這行");
			return "3";

		} catch (Exception e) {
			logger.error(e);
			System.out.println("*****");
		
			return "1";
		}

		return msg;
	}

testDao

public void createOrder(final String orderno)throws Exception{
		
		String sql=" INSERT  INTO ORDER ( ORDER_NO ) "
				+"  VALUES(?) ";
	
		oracleJdbcTemplate.update(sql,  new PreparedStatementSetter() {
            public void setValues(PreparedStatement ps) throws SQLException {
            
            		ps.setString(1,orderno);
            	
            		}	
			}		);
	}

請問該如何改?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
headmo
iT邦新手 5 級 ‧ 2019-08-15 17:46:45
最佳解答

it is because the Exception throws is NOT SQLDataException.

So you should first make sure what excepttion is it.

change the line from :

} catch (Exception e) {
			logger.error(e);
			System.out.println("*****");
			return "1";
		}

to

} catch (Exception e) {
            e.printStackTrace() ;
			System.out.println("*****"+e.getClass().getName());
			return "1";
		}

Check what kind of exception is it.

or you can post the error log here for reference.

我要發表回答

立即登入回答