ca.krasnay.sqlbuilder
Class ParameterizedPreparedStatementCreator

java.lang.Object
  extended by ca.krasnay.sqlbuilder.ParameterizedPreparedStatementCreator
All Implemented Interfaces:
Serializable, Cloneable, org.springframework.jdbc.core.PreparedStatementCreator

public class ParameterizedPreparedStatementCreator
extends Object
implements Cloneable, org.springframework.jdbc.core.PreparedStatementCreator, Serializable

Implementation of Spring's PreparedStatementCreator that allows for the substitution of named parameters. Here's a simple example:

 PreparedStatement ps = new ParameterizedPreparedStatementCreator().setSql(
         "select * from Employee where name like :name").setParameter("name", "Bob%").createPreparedStatement(conn);
 
The implementation performs simple text substitution of parameters, which can lead to problems with things like this: "select * from Employee where name = 'foo:bar'" In this case, createPreparedStatement(Connection) will fail if the bar is not defined, or will result in "select * from Employee where name = 'foo?'", both of which are wrong.

Author:
John Krasnay
See Also:
Serialized Form

Constructor Summary
  ParameterizedPreparedStatementCreator()
           
protected ParameterizedPreparedStatementCreator(ParameterizedPreparedStatementCreator other)
          Copy constructor.
 
Method Summary
 ParameterizedPreparedStatementCreator clone()
           
 PreparedStatement createPreparedStatement(Connection con)
           
 Map<String,Object> getParameterMap()
           
 String getSql()
           
 ParameterizedPreparedStatementCreator setParameter(String name, Object value)
           
 ParameterizedPreparedStatementCreator setSql(String sql)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParameterizedPreparedStatementCreator

public ParameterizedPreparedStatementCreator()

ParameterizedPreparedStatementCreator

protected ParameterizedPreparedStatementCreator(ParameterizedPreparedStatementCreator other)
Copy constructor. Used by clone().

Parameters:
other - ParameterizedPreparedStatementCreator being cloned.
Method Detail

clone

public ParameterizedPreparedStatementCreator clone()
Overrides:
clone in class Object

createPreparedStatement

public PreparedStatement createPreparedStatement(Connection con)
                                          throws SQLException
Specified by:
createPreparedStatement in interface org.springframework.jdbc.core.PreparedStatementCreator
Throws:
SQLException

getParameterMap

public Map<String,Object> getParameterMap()

getSql

public String getSql()

setParameter

public ParameterizedPreparedStatementCreator setParameter(String name,
                                                          Object value)

setSql

public ParameterizedPreparedStatementCreator setSql(String sql)


Copyright © 2014. All rights reserved.