91-9990449935 0120-4256464 |
Spring NamedParameterJdbcTemplate ExampleSpring provides another way to insert data by named parameter. In such way, we use names instead of ?(question mark). So it is better to remember the data for the column. Simple example of named parameter query
Method of NamedParameterJdbcTemplate classIn this example,we are going to call only the execute method of NamedParameterJdbcTemplate class. Syntax of the method is as follows: Example of NamedParameterJdbcTemplate classWe are assuming that you have created the following table inside the Oracle10g database. Employee.javaThis class contains 3 properties with constructors and setter and getters. EmployeeDao.javaIt contains on property jdbcTemplate and one method save. applicationContext.xmlThe DriverManagerDataSource is used to contain the information about the database such as driver class name, connnection URL, username and password. There are a property named datasource in the NamedParameterJdbcTemplate class of DriverManagerDataSource type. So, we need to provide the reference of DriverManagerDataSource object in the NamedParameterJdbcTemplate class for the datasource property. Here, we are using the NamedParameterJdbcTemplate object in the EmployeeDao class, so we are passing it by the constructor but you can use setter method also. SimpleTest.javaThis class gets the bean from the applicationContext.xml file and calls the save method.
download this example (developed using MyEclipse IDE)
download this example (developed using Eclipse IDE)
Next TopicSpring SimpleJdbcTemplate Example
|