Sli*_*lim 0 java prepared-statement jboss7.x
我有这个代码:
Helper helper = getDBhelper();
Connection conn = helper.getConnection();
String sql =
" SELECT DISTINCT date as plannedDate" +
" FROM plan ";
String AssimilationTabDates =
" SELECT DISTINCT payment as plannedDate " +
" FROM credit_mo_assimilation_tab ";
String assimilationInfoDates =
" SELECT DISTINCT planned_pay as plannedDate " +
" FROM assimilation ";
String sqlUpdate =
" UPDATE plan " +
" SET date = ? " +
" WHERE planned_date = ? ";
String updateAssimilationTab =
" UPDATE assimilation " +
" SET payment = to_date(?, 'DD-MM-YYYY') " +
" WHERE d_payment = to_date(?, 'DD-MM-YYYY') ";
String updateAssimilationInfo =
" UPDATE assimilation " +
" SET pay = to_date(?, 'DD-MM-YYYY') " +
" WHERE planned_pay = ? ";
PreparedStatement ps = null;
ResultSet rs = null;
Date plannedDate = null;
List<String> plannedDates = new ArrayList<String>();
List<String> plannedTabDates = new ArrayList<String>();
List<String> plannedInfoDates = new ArrayList<String>();
try {
ps = conn.prepareStatement(sql);
ps.execute();
rs = ps.getResultSet();
while(rs.next()) {
plannedDate = rs.getDate("plannedDate");
String plannedD = new SimpleDateFormat("dd-MMM-yy").format(plannedDate);
plannedDates.add(plannedD);
}
ps = conn.prepareStatement(AssimilationTabDates);
ps.execute();
rs = ps.getResultSet();
while(rs.next()) {
plannedDate = rs.getDate("plannedDate");
String plannedD = null;
if(plannedDate != null){
plannedD = new SimpleDateFormat("dd-MMM-yy").format(plannedDate);
}
if(plannedD != null){
plannedTabDates.add(plannedD);
}
}
ps = conn.prepareStatement(assimilationInfoDates);
ps.execute();
rs = ps.getResultSet();
while(rs.next()) {
plannedDate = rs.getDate("plannedDate");
String plannedD = new SimpleDateFormat("dd-MMM-yy").format(plannedDate);
plannedInfoDates.add(plannedD);
}
} catch (Exception ex) {
ex.printStackTrace();
}
try{
for( String oneItem : plannedDates ) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
Date datePlanned = formatter.parse(oneItem);
Date paymentDate = datePlanned;
Date paymentDateReal = paymentDate;
if (paymentDate != null) {
paymentDateReal = DefaultProdCalendar.findNearestWorkingDay(paymentDate);
}
String realDate = new SimpleDateFormat("dd-MMM-yy").format(paymentDateReal);
ps = conn.prepareStatement(sqlUpdate);
ps.setString(1, realDate);
ps.setString(2, oneItem);
ps.execute();
rs = ps.getResultSet();
}
for( String oneItem : plannedTabDates ) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
Date datePlanned = formatter.parse(oneItem);
Date paymentDate = datePlanned;
Date paymentDateReal = paymentDate;
if (paymentDate != null) {
paymentDateReal = DefaultProdCalendar.findNearestWorkingDay(paymentDate);
}
String realDate = new SimpleDateFormat("dd-MMM-yy").format(paymentDateReal);
ps = conn.prepareStatement(updateAssimilationTab);
ps.setString(1, realDate);
ps.setString(2, oneItem);
ps.execute();
rs = ps.getResultSet();
}
for( String oneItem : plannedInfoDates ) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
Date datePlanned = formatter.parse(oneItem);
Date paymentDate = datePlanned;
Date paymentDateReal = paymentDate;
if (paymentDate != null) {
paymentDateReal = DefaultProdCalendar.findNearestWorkingDay(paymentDate);
}
String realDate = new SimpleDateFormat("dd-MMM-yy").format(paymentDateReal);
ps = conn.prepareStatement(updateAssimilationInfo);
ps.setString(1, realDate);
ps.setString(2, oneItem);
ps.execute();
rs = ps.getResultSet();
}
}catch(Exception e){
e.printStackTrace();
}
try {
ps = conn.prepareStatement(sql);
ps.execute();
rs = ps.getResultSet();
while(rs.next()) {
plannedDate = rs.getDate("plannedDate");
String plannedD = new SimpleDateFormat("dd-MMM-yy").format(plannedDate);
plannedDates.add(plannedD);
}
ps = conn.prepareStatement(AssimilationTabDates);
ps.execute();
rs = ps.getResultSet();
while(rs.next()) {
plannedDate = rs.getDate("plannedDate");
String plannedD = null;
if(plannedDate != null){
plannedD = new SimpleDateFormat("dd-MMM-yy").format(plannedDate);
}
if(plannedD != null){
plannedTabDates.add(plannedD);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
try{
for( String oneItem : plannedDates ) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
Date datePlanned = formatter.parse(oneItem);
Date paymentDate = datePlanned;
Date paymentDateReal = paymentDate;
if (paymentDate != null) {
paymentDateReal = DefaultProdCalendar.findNearestWorkingDay(paymentDate);
}
String realDate = new SimpleDateFormat("dd-MMM-yy").format(paymentDateReal);
ps = conn.prepareStatement(sqlUpdate);
ps.setString(1, realDate);
ps.setString(2, oneItem);
ps.execute();
rs = ps.getResultSet();
}
for( String oneItem : plannedTabDates ) {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
Date datePlanned = formatter.parse(oneItem);
Date paymentDate = datePlanned;
Date paymentDateReal = paymentDate;
if (paymentDate != null) {
paymentDateReal = DefaultProdCalendar.findNearestWorkingDay(paymentDate);
}
String realDate = new SimpleDateFormat("dd-MMM-yy").format(paymentDateReal);
ps = conn.prepareStatement(updateAssimilationTab);
ps.setString(1, realDate);
ps.setString(2, oneItem);
ps.execute();
rs = ps.getResultSet();
}
}catch(Exception e){
e.printStackTrace();
}
finally {
try {
ps.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码运行得很好,但是有一个小问题.该语句没有被关闭,所以这推动我的jboss服务器执行它并且几乎所有查询执行都会引发以下错误:
Closing a statement you left open, please do your own housekeeping: java.lang.Throwable: STACKTRACE
Run Code Online (Sandbox Code Playgroud)
是不是
ps.close();
conn.close();
Run Code Online (Sandbox Code Playgroud)
在finally应该关闭的一切吗?
我知道我错过了一些非常小而简单的东西,但我现在无法发现它.
| 归档时间: |
|
| 查看次数: |
281 次 |
| 最近记录: |