@@ -2971,7 +2971,6 @@ in the primitive wrapper classes explicitly or using auto-boxing.
2971
2971
[subs="verbatim,quotes"]
2972
2972
----
2973
2973
import javax.sql.DataSource;
2974
-
2975
2974
import org.springframework.jdbc.core.JdbcTemplate;
2976
2975
2977
2976
public class ExecuteAnUpdate {
@@ -4018,7 +4017,7 @@ data from the `t_actor` relation to an instance of the `Actor` class.
4018
4017
4019
4018
public ActorMappingQuery(DataSource ds) {
4020
4019
super(ds, "select id, first_name, last_name from t_actor where id = ?");
4021
- super. declareParameter(new SqlParameter("id", Types.INTEGER));
4020
+ declareParameter(new SqlParameter("id", Types.INTEGER));
4022
4021
compile();
4023
4022
}
4024
4023
@@ -4039,7 +4038,7 @@ for this customer query takes the `DataSource` as the only parameter. In this
4039
4038
constructor you call the constructor on the superclass with the `DataSource` and the SQL
4040
4039
that should be executed to retrieve the rows for this query. This SQL will be used to
4041
4040
create a `PreparedStatement` so it may contain place holders for any parameters to be
4042
- passed in during execution.You must declare each parameter using the `declareParameter`
4041
+ passed in during execution. You must declare each parameter using the `declareParameter`
4043
4042
method passing in an `SqlParameter`. The `SqlParameter` takes a name and the JDBC type
4044
4043
as defined in `java.sql.Types`. After you define all parameters, you call the
4045
4044
`compile()` method so the statement can be prepared and later executed. This class is
@@ -4092,9 +4091,7 @@ class since it can easily be parameterized by setting SQL and declaring paramete
4092
4091
[subs="verbatim"]
4093
4092
----
4094
4093
import java.sql.Types;
4095
-
4096
4094
import javax.sql.DataSource;
4097
-
4098
4095
import org.springframework.jdbc.core.SqlParameter;
4099
4096
import org.springframework.jdbc.object.SqlUpdate;
4100
4097
@@ -4173,9 +4170,7 @@ output parameter, in this case only one, using the parameter name as the key.
4173
4170
import java.util.Date;
4174
4171
import java.util.HashMap;
4175
4172
import java.util.Map;
4176
-
4177
4173
import javax.sql.DataSource;
4178
-
4179
4174
import org.springframework.beans.factory.annotation.Autowired;
4180
4175
import org.springframework.jdbc.core.SqlOutParameter;
4181
4176
import org.springframework.jdbc.object.StoredProcedure;
@@ -4222,14 +4217,13 @@ Oracle REF cursors).
4222
4217
[source,java,indent=0]
4223
4218
[subs="verbatim,quotes"]
4224
4219
----
4220
+ import java.util.HashMap;
4221
+ import java.util.Map;
4222
+ import javax.sql.DataSource;
4225
4223
import oracle.jdbc.OracleTypes;
4226
4224
import org.springframework.jdbc.core.SqlOutParameter;
4227
4225
import org.springframework.jdbc.object.StoredProcedure;
4228
4226
4229
- import javax.sql.DataSource;
4230
- import java.util.HashMap;
4231
- import java.util.Map;
4232
-
4233
4227
public class TitlesAndGenresStoredProcedure extends StoredProcedure {
4234
4228
4235
4229
private static final String SPROC_NAME = "AllTitlesAndGenres";
@@ -4259,12 +4253,10 @@ the supplied `ResultSet`:
4259
4253
[source,java,indent=0]
4260
4254
[subs="verbatim,quotes"]
4261
4255
----
4262
- import org.springframework.jdbc.core.RowMapper;
4263
-
4264
4256
import java.sql.ResultSet;
4265
4257
import java.sql.SQLException;
4266
-
4267
4258
import com.foo.domain.Title;
4259
+ import org.springframework.jdbc.core.RowMapper;
4268
4260
4269
4261
public final class TitleMapper implements RowMapper<Title> {
4270
4262
@@ -4283,12 +4275,10 @@ the supplied `ResultSet`.
4283
4275
[source,java,indent=0]
4284
4276
[subs="verbatim,quotes"]
4285
4277
----
4286
- import org.springframework.jdbc.core.RowMapper;
4287
-
4288
4278
import java.sql.ResultSet;
4289
4279
import java.sql.SQLException;
4290
-
4291
4280
import com.foo.domain.Genre;
4281
+ import org.springframework.jdbc.core.RowMapper;
4292
4282
4293
4283
public final class GenreMapper implements RowMapper<Genre> {
4294
4284
@@ -4306,17 +4296,15 @@ delegate to the superclass' untyped `execute(Map parameters)` method (which has
4306
4296
[source,java,indent=0]
4307
4297
[subs="verbatim,quotes"]
4308
4298
----
4309
- import oracle.jdbc.OracleTypes;
4310
- import org.springframework.jdbc.core.SqlOutParameter;
4311
- import org.springframework.jdbc.core.SqlParameter;
4312
- import org.springframework.jdbc.object.StoredProcedure;
4313
-
4314
- import javax.sql.DataSource;
4315
-
4316
4299
import java.sql.Types;
4317
4300
import java.util.Date;
4318
4301
import java.util.HashMap;
4319
4302
import java.util.Map;
4303
+ import javax.sql.DataSource;
4304
+ import oracle.jdbc.OracleTypes;
4305
+ import org.springframework.jdbc.core.SqlOutParameter;
4306
+ import org.springframework.jdbc.core.SqlParameter;
4307
+ import org.springframework.jdbc.object.StoredProcedure;
4320
4308
4321
4309
public class TitlesAfterDateStoredProcedure extends StoredProcedure {
4322
4310
@@ -4411,6 +4399,7 @@ dependency injection.
4411
4399
final File clobIn = new File("large.txt");
4412
4400
final InputStream clobIs = new FileInputStream(clobIn);
4413
4401
final InputStreamReader clobReader = new InputStreamReader(clobIs);
4402
+
4414
4403
jdbcTemplate.execute(
4415
4404
"INSERT INTO lob_table (id, a_clob, a_blob) VALUES (?, ?, ?)",
4416
4405
new AbstractLobCreatingPreparedStatementCallback(lobHandler) { # <1>
@@ -4421,6 +4410,7 @@ dependency injection.
4421
4410
}
4422
4411
}
4423
4412
);
4413
+
4424
4414
blobIs.close();
4425
4415
clobReader.close();
4426
4416
----
@@ -4507,21 +4497,24 @@ declaration of an `SqlOutParameter`.
4507
4497
[source,java,indent=0]
4508
4498
[subs="verbatim,quotes"]
4509
4499
----
4510
- final TestItem = new TestItem(123L, "A test item",
4511
- new SimpleDateFormat("yyyy-M-d").parse("2010-12-31"));
4500
+ public class TestItemStoredProcedure extends StoredProcedure {
4512
4501
4513
- declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE",
4514
- new SqlReturnType() {
4515
- public Object getTypeValue(CallableStatement cs, int colIndx, int sqlType, String typeName) throws SQLException {
4516
- STRUCT struct = (STRUCT) cs.getObject(colIndx);
4517
- Object[] attr = struct.getAttributes();
4518
- TestItem item = new TestItem();
4519
- item.setId(((Number) attr[0]).longValue());
4520
- item.setDescription((String) attr[1]);
4521
- item.setExpirationDate((java.util.Date) attr[2]);
4522
- return item;
4523
- }
4524
- }));
4502
+ public TestItemStoredProcedure(DataSource dataSource) {
4503
+ ...
4504
+ declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE",
4505
+ new SqlReturnType() {
4506
+ public Object getTypeValue(CallableStatement cs, int colIndx, int sqlType, String typeName) throws SQLException {
4507
+ STRUCT struct = (STRUCT) cs.getObject(colIndx);
4508
+ Object[] attr = struct.getAttributes();
4509
+ TestItem item = new TestItem();
4510
+ item.setId(((Number) attr[0]).longValue());
4511
+ item.setDescription((String) attr[1]);
4512
+ item.setExpirationDate((java.util.Date) attr[2]);
4513
+ return item;
4514
+ }
4515
+ }));
4516
+ ...
4517
+ }
4525
4518
----
4526
4519
4527
4520
You use the `SqlTypeValue` to pass in the value of a Java object like `TestItem` into a
@@ -4533,7 +4526,7 @@ the following example, or ``ArrayDescriptor``s.
4533
4526
[source,java,indent=0]
4534
4527
[subs="verbatim,quotes"]
4535
4528
----
4536
- final TestItem = new TestItem(123L, "A test item",
4529
+ final TestItem testItem = new TestItem(123L, "A test item",
4537
4530
new SimpleDateFormat("yyyy-M-d").parse("2010-12-31"));
4538
4531
4539
4532
SqlTypeValue value = new AbstractSqlTypeValue() {
@@ -6544,7 +6537,6 @@ constructs a Spring application context, and calls these two methods.
6544
6537
import java.io.IOException;
6545
6538
import javax.xml.transform.stream.StreamResult;
6546
6539
import javax.xml.transform.stream.StreamSource;
6547
-
6548
6540
import org.springframework.context.ApplicationContext;
6549
6541
import org.springframework.context.support.ClassPathXmlApplicationContext;
6550
6542
import org.springframework.oxm.Marshaller;
0 commit comments