SqlTools

Die Klasse SQLTools stellt statische Hilfsmethoden Methoden zur Verfügung, welche immer wieder benötigt werden. So z.B. das Schließen von einer Connection, oder das Zurückgeben von NULL werde bei numerischen Werten.

SqlTools.java


package de.snowbits.tools;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SQLTools {

	private SQLTools() { }
	
	public static final Integer getInteger(ResultSet rs, String columnName) throws SQLException {
	    int result = rs.getInt(columnName);
		
	    return rs.wasNull() ? null : result;
	}
	
	public static final Long getLong(ResultSet rs, String columnName) throws SQLException {
		long result = rs.getLong(columnName);
		
		return rs.wasNull() ? null : result;
	}
	
	public static final Float getFloat(ResultSet rs, String columnName) throws SQLException {
		float result = rs.getFloat(columnName);
	
		return rs.wasNull() ? null : result;
	}
	
	public static final Double getDouble(ResultSet rs, String columnName) throws SQLException {
		double result = rs.getDouble(columnName);
	
		return rs.wasNull() ? null : result;
	}
	
	public static final void close(Connection conn) throws SQLException {
		if (conn != null)
			conn.close();
	}	
	
	public static final void close(Statement stmt, Connection conn) throws SQLException {
		if (stmt != null)
			stmt.close();
		if (conn != null)
			conn.close();
	}	
	
	public static final void close(Statement stmt) throws SQLException {
		if (stmt != null)
			stmt.close();
	}	
	
	public static final void close(ResultSet rs, Statement stmt) throws SQLException {
		if (rs != null)
			rs.close();
		if (stmt != null)
			stmt.close();
	}
	
	public static final void close(ResultSet rs, Statement stmt, Connection conn) throws SQLException {
		if (rs != null)
			rs.close();
		if (stmt != null)
			stmt.close();
		if (conn != null)
			conn.close();
	}
		
}
	

Top


Example
Sitemap Kontakt Impressum