1 19 20 package com.sslexplorer.jdbc; 21 22 import java.sql.Connection ; 23 import java.sql.ResultSet ; 24 import java.sql.SQLException ; 25 import java.sql.Statement ; 26 import java.sql.Timestamp ; 27 import java.util.Calendar ; 28 29 34 public class JDBCUtil { 35 44 public static boolean isNull(ResultSet resultSet, String columnName) throws SQLException { 45 return null == resultSet.getObject(columnName); 46 } 47 48 57 public static Calendar getCalendar(ResultSet resultSet, String columnName) throws SQLException { 58 return getCalendar(resultSet.getTimestamp(columnName)); 59 } 60 61 67 public static Calendar getCalendar(Timestamp timestamp) { 68 Calendar calendar = Calendar.getInstance(); 69 calendar.setTimeInMillis(timestamp == null ? System.currentTimeMillis() : timestamp.getTime()); 70 return calendar; 71 } 72 73 77 public static void cleanup(Connection connection) { 78 if (connection != null) { 79 try { 80 connection.close(); 81 } catch (SQLException e) { 82 } 84 } 85 } 86 87 91 public static void cleanup(Statement statement) { 92 if(statement != null) { 93 try { 94 statement.close(); 95 } catch (SQLException e) { 96 } 98 } 99 } 100 101 105 public static void cleanup(JDBCPreparedStatement statement) { 106 if(statement != null) { 107 try { 108 statement.releasePreparedStatement(); 109 } catch (SQLException e) { 110 } 112 } 113 } 114 115 119 public static void cleanup(ResultSet resultSet) { 120 if (resultSet != null) { 121 try { 122 resultSet.close(); 123 } catch (SQLException e) { 124 } 126 } 127 } 128 } | Popular Tags |