Accessing a JDBC Resource

If you create a property named jdbcr of type JDBC Resource Template, TIBCO Business Studio adds the following to the abstract implementation class:
import org.osoa.sca.annotations.Property;
import javax.sql.DataSource;

private DataSource jdbcr;

	@Property(name = "jdbcr")
	public void setDbr(DataSource jdbcr) {
		this.jdbcr = jdbcr;
	}

	public DataSource getJdbcr() {
		return jdbcr;
	}

Procedure

  • Invoke the accessor methods in your component implementation.

Example

import javax.sql.DataSource;
	DataSource ds = getJdbcr();
	Connection connection = null;
	
	try {
		connection = ds.getConnection();
		ensureTablesExist(connection);	
		
		Statement stmt = connection.createStatement();
		ResultSet rs = stmt.executeQuery(sqlString);
		PhoneEntryType entry = null;
		
		while(rs.next()) {
			entry = resp.addNewOut();
			entry.setEntryId(rs.getString("id"));
			entry.setFirstName(rs.getString("firstName"));
			entry.setLastName(rs.getString("lastName"));
			entry.setPhone(rs.getString("phone"));			
		}

	} catch(SQLException e) {
		e.printStackTrace();
	} finally {
		try{
			connection.close();
		}catch(Exception e){};
			...
		}
	}