Java Reference
In-Depth Information
<bean id="datasource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="einsureDatasource" />
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">
org.jnp.interfaces.NamingContextFactory
</prop>
<prop key="java.naming.provider.url">
jnp://localhost:1099
</prop>
<prop key="java.naming.factory.url.pkgs">
org.jboss.naming.client
</prop>
</props>
</property>
</bean>
</beans>
Using Bind Variables
The SQL query in Listings 5-1 and 5-3 uses positional bind variables denoted by ? , which
are static. Any change in the position of the bind variable will lead to a change in the
code that sets this variable value. In Listing 5-1, the arguments in the method call
PreparedStatement.setXXX will be affected. Similarly, in Listing 5-3, the position of the
array elements would have to be altered to accommodate the query change.
Spring JDBC provides a convenient solution to this with support for named bind
variables denoted by :variable_name . To use this feature, you should change the SQL
query as shown in Listing 5-7. Note that the signature of the savePolicyDetails method
has also changed, and it now takes a Map object as an argument.
Listing 5-7. PolicyDao.java
public interface PolicyDetailDao {
String SAVE_POLICY_DETAILS_SQL = " insert into T_POLICY_DETAIL
values(T_POLICY_DETAIL_SEQ.nextval,
:productCd,:name,:age)";
public void savePolicyDetails(Map policyDetailMap);
}
 
 
Search WWH ::




Custom Search