Code example for Connection

Methods: closeisClosedprepareStatement

0
	public Rule getRuleById(int id) {
		Rule rule = new Rule();
		Connection conn = null;
		try { 
			conn = dataSource.getConnection();
			PreparedStatement ps = conn.prepareStatement(SELECT + "where r.id = ?");
			ps.setInt(1, id);
			ResultSet set = ps.executeQuery();
			if (set.next()) {
				rule.setId(set.getInt("id"));
				rule.setPluginRuleKey(set.getString("plugin_rule_key"));
				rule.setPluginName(set.getString("plugin_name"));
				rule.setDescription(set.getString("description"));
				rule.setCardinality(set.getString("cardinality"));
				rule.setParentId(set.getInt("parent_id"));
				rule.setName(set.getString("name"));
				rule.setPriority(set.getInt("priority"));
			} 
		} catch (SQLException e1) {
			e1.printStackTrace();
		} finally { 
			try { 
				if (conn != null && !conn.isClosed()) {
					conn.close();
				} 
			} catch (SQLException e) {
				e.printStackTrace();
			} 
		} 
Connect your IDE to all the code out there  Get Codota for Java