@@ -2982,7 +2982,6 @@ in the primitive wrapper classes explicitly or using auto-boxing.
2982
2982
[subs="verbatim,quotes"]
2983
2983
----
2984
2984
import javax.sql.DataSource;
2985
-
2986
2985
import org.springframework.jdbc.core.JdbcTemplate;
2987
2986
2988
2987
public class ExecuteAnUpdate {
@@ -4023,7 +4022,7 @@ data from the `t_actor` relation to an instance of the `Actor` class.
4023
4022
4024
4023
public ActorMappingQuery(DataSource ds) {
4025
4024
super(ds, "select id, first_name, last_name from t_actor where id = ?");
4026
- super. declareParameter(new SqlParameter("id", Types.INTEGER));
4025
+ declareParameter(new SqlParameter("id", Types.INTEGER));
4027
4026
compile();
4028
4027
}
4029
4028
@@ -4044,7 +4043,7 @@ for this customer query takes the `DataSource` as the only parameter. In this
4044
4043
constructor you call the constructor on the superclass with the `DataSource` and the SQL
4045
4044
that should be executed to retrieve the rows for this query. This SQL will be used to
4046
4045
create a `PreparedStatement` so it may contain place holders for any parameters to be
4047
- passed in during execution.You must declare each parameter using the `declareParameter`
4046
+ passed in during execution. You must declare each parameter using the `declareParameter`
4048
4047
method passing in an `SqlParameter`. The `SqlParameter` takes a name and the JDBC type
4049
4048
as defined in `java.sql.Types`. After you define all parameters, you call the
4050
4049
`compile()` method so the statement can be prepared and later executed. This class is
@@ -4097,9 +4096,7 @@ class since it can easily be parameterized by setting SQL and declaring paramete
4097
4096
[subs="verbatim"]
4098
4097
----
4099
4098
import java.sql.Types;
4100
-
4101
4099
import javax.sql.DataSource;
4102
-
4103
4100
import org.springframework.jdbc.core.SqlParameter;
4104
4101
import org.springframework.jdbc.object.SqlUpdate;
4105
4102
@@ -4178,9 +4175,7 @@ output parameter, in this case only one, using the parameter name as the key.
4178
4175
import java.util.Date;
4179
4176
import java.util.HashMap;
4180
4177
import java.util.Map;
4181
-
4182
4178
import javax.sql.DataSource;
4183
-
4184
4179
import org.springframework.beans.factory.annotation.Autowired;
4185
4180
import org.springframework.jdbc.core.SqlOutParameter;
4186
4181
import org.springframework.jdbc.object.StoredProcedure;
@@ -4227,14 +4222,13 @@ Oracle REF cursors).
4227
4222
[source,java,indent=0]
4228
4223
[subs="verbatim,quotes"]
4229
4224
----
4225
+ import java.util.HashMap;
4226
+ import java.util.Map;
4227
+ import javax.sql.DataSource;
4230
4228
import oracle.jdbc.OracleTypes;
4231
4229
import org.springframework.jdbc.core.SqlOutParameter;
4232
4230
import org.springframework.jdbc.object.StoredProcedure;
4233
4231
4234
- import javax.sql.DataSource;
4235
- import java.util.HashMap;
4236
- import java.util.Map;
4237
-
4238
4232
public class TitlesAndGenresStoredProcedure extends StoredProcedure {
4239
4233
4240
4234
private static final String SPROC_NAME = "AllTitlesAndGenres";
@@ -4264,12 +4258,10 @@ the supplied `ResultSet`:
4264
4258
[source,java,indent=0]
4265
4259
[subs="verbatim,quotes"]
4266
4260
----
4267
- import org.springframework.jdbc.core.RowMapper;
4268
-
4269
4261
import java.sql.ResultSet;
4270
4262
import java.sql.SQLException;
4271
-
4272
4263
import com.foo.domain.Title;
4264
+ import org.springframework.jdbc.core.RowMapper;
4273
4265
4274
4266
public final class TitleMapper implements RowMapper<Title> {
4275
4267
@@ -4288,12 +4280,10 @@ the supplied `ResultSet`.
4288
4280
[source,java,indent=0]
4289
4281
[subs="verbatim,quotes"]
4290
4282
----
4291
- import org.springframework.jdbc.core.RowMapper;
4292
-
4293
4283
import java.sql.ResultSet;
4294
4284
import java.sql.SQLException;
4295
-
4296
4285
import com.foo.domain.Genre;
4286
+ import org.springframework.jdbc.core.RowMapper;
4297
4287
4298
4288
public final class GenreMapper implements RowMapper<Genre> {
4299
4289
@@ -4311,17 +4301,15 @@ delegate to the superclass' untyped `execute(Map parameters)` method (which has
4311
4301
[source,java,indent=0]
4312
4302
[subs="verbatim,quotes"]
4313
4303
----
4314
- import oracle.jdbc.OracleTypes;
4315
- import org.springframework.jdbc.core.SqlOutParameter;
4316
- import org.springframework.jdbc.core.SqlParameter;
4317
- import org.springframework.jdbc.object.StoredProcedure;
4318
-
4319
- import javax.sql.DataSource;
4320
-
4321
4304
import java.sql.Types;
4322
4305
import java.util.Date;
4323
4306
import java.util.HashMap;
4324
4307
import java.util.Map;
4308
+ import javax.sql.DataSource;
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;
4325
4313
4326
4314
public class TitlesAfterDateStoredProcedure extends StoredProcedure {
4327
4315
@@ -4416,6 +4404,7 @@ dependency injection.
4416
4404
final File clobIn = new File("large.txt");
4417
4405
final InputStream clobIs = new FileInputStream(clobIn);
4418
4406
final InputStreamReader clobReader = new InputStreamReader(clobIs);
4407
+
4419
4408
jdbcTemplate.execute(
4420
4409
"INSERT INTO lob_table (id, a_clob, a_blob) VALUES (?, ?, ?)",
4421
4410
new AbstractLobCreatingPreparedStatementCallback(lobHandler) { # <1>
@@ -4426,6 +4415,7 @@ dependency injection.
4426
4415
}
4427
4416
}
4428
4417
);
4418
+
4429
4419
blobIs.close();
4430
4420
clobReader.close();
4431
4421
----
@@ -4512,21 +4502,24 @@ declaration of an `SqlOutParameter`.
4512
4502
[source,java,indent=0]
4513
4503
[subs="verbatim,quotes"]
4514
4504
----
4515
- final TestItem = new TestItem(123L, "A test item",
4516
- new SimpleDateFormat("yyyy-M-d").parse("2010-12-31"));
4505
+ public class TestItemStoredProcedure extends StoredProcedure {
4517
4506
4518
- declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE",
4519
- new SqlReturnType() {
4520
- public Object getTypeValue(CallableStatement cs, int colIndx, int sqlType, String typeName) throws SQLException {
4521
- STRUCT struct = (STRUCT) cs.getObject(colIndx);
4522
- Object[] attr = struct.getAttributes();
4523
- TestItem item = new TestItem();
4524
- item.setId(((Number) attr[0]).longValue());
4525
- item.setDescription((String) attr[1]);
4526
- item.setExpirationDate((java.util.Date) attr[2]);
4527
- return item;
4528
- }
4529
- }));
4507
+ public TestItemStoredProcedure(DataSource dataSource) {
4508
+ ...
4509
+ declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE",
4510
+ new SqlReturnType() {
4511
+ public Object getTypeValue(CallableStatement cs, int colIndx, int sqlType, String typeName) throws SQLException {
4512
+ STRUCT struct = (STRUCT) cs.getObject(colIndx);
4513
+ Object[] attr = struct.getAttributes();
4514
+ TestItem item = new TestItem();
4515
+ item.setId(((Number) attr[0]).longValue());
4516
+ item.setDescription((String) attr[1]);
4517
+ item.setExpirationDate((java.util.Date) attr[2]);
4518
+ return item;
4519
+ }
4520
+ }));
4521
+ ...
4522
+ }
4530
4523
----
4531
4524
4532
4525
You use the `SqlTypeValue` to pass in the value of a Java object like `TestItem` into a
@@ -4538,7 +4531,7 @@ the following example, or ``ArrayDescriptor``s.
4538
4531
[source,java,indent=0]
4539
4532
[subs="verbatim,quotes"]
4540
4533
----
4541
- final TestItem = new TestItem(123L, "A test item",
4534
+ final TestItem testItem = new TestItem(123L, "A test item",
4542
4535
new SimpleDateFormat("yyyy-M-d").parse("2010-12-31"));
4543
4536
4544
4537
SqlTypeValue value = new AbstractSqlTypeValue() {
@@ -6257,7 +6250,6 @@ constructs a Spring application context, and calls these two methods.
6257
6250
import java.io.IOException;
6258
6251
import javax.xml.transform.stream.StreamResult;
6259
6252
import javax.xml.transform.stream.StreamSource;
6260
-
6261
6253
import org.springframework.context.ApplicationContext;
6262
6254
import org.springframework.context.support.ClassPathXmlApplicationContext;
6263
6255
import org.springframework.oxm.Marshaller;
0 commit comments