Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
14 views
11 pages
P 18
spring
Uploaded by
tresbonarchitecte
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save p18 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
14 views
11 pages
P 18
spring
Uploaded by
tresbonarchitecte
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save p18 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save p18 For Later
You are on page 1
/ 11
Search
Fullscreen
0/10/2028 09:07 ‘Spring JdocTemplate Tutorial -javatpoint MailAPI Hibernate Spring Android tips: javatpeint.comispring-Jdbe Tempate-tuloral un0/10/2028 09:07 ‘Spring JdocTemplate Tutorial -javatpoint Spring JdbcTemplate Tutorial Spring JdbeTemplate is a powerful mechanism to connect to the database and execute SQL queries, It internally uses JDBC api, but eliminates a lot of problems of JDBC API Problems of JDBC API The problems of JDBC API are as follows ° We need to write a lot of code before and after executing the query, such as creating connection, statement, closing resultset, connection etc. ° We need to perform exception handling code on the database logic. ° We need to handle transaction. ° Repetition of all these codes from one to another database logic is a time consuming task. Advantage of Spring JdbcTemplate Spring JdbcTemplate eliminates all the above mentioned problems of JDBC API. It provides you methods to write the queries directly, so it saves a lot of work and time. tips: javatpeint.comisoring-Jdbe Tempate-tuloral an0/10/2028 09:07 Spring JdocTemplate Tutorial -javatpoint oo — DX Spring Jdbc Approaches Spring framework provides following approaches for JDBC database access: nites javatpointconvspring-IdbeTemplate-tutorial an0/10/2028 09:07 ‘Spring JdocTemplate Tutorial -javatpoint ° JdbcTemplate ° NamedParameterldbcTemplate ° SimpleJdbcTemplate ° ‘Simpleldbcinsert and SimpleJdbcCall JdbcTemplate class It is the central class in the Spring JDBC support classes. It takes care of creation and release of resources such as creating and closing of connection object etc. So it will not lead to any problem if you forget to close the connection. It handles the exception and provides the informative exception messages by the help of excepion classes defined in the org.springframework.dao package, We can perform all the database operations by the help of JdbcTemplate class such as insertion, updation, deletion and retrieval of the data from the database. Let's see the methods of spring JdbcTemplate class. No. Method Description 1) public int update(String query) is used to insert, update and delete records. 2) public int update(String query,Object.. is used to insert, update and delete records args) using PreparedStatement using given arguments. 3) public void execute(String query) is used to execute DDL query. 4) public T —execute(String sql, executes the = query. ~=—sby—_using PreparedStatementCallback action) PreparedStatement callback 5) public T ~~ query(String sql, is used to. fetch_~— records. using ResultSetExtractor rse) ResultSetExtractor. 6) public List query(String sql, RowMapper is used to fetch records using RowMapper. rse) tips: javatpeint.comispring-Jdbe Tempate-tuloral an0/10/2028 09:07 ‘Spring JdocTemplate Tutorial -javatpoint Example of Spring JdbcTemplate We are assuming that you have created the following table inside the Oracle10g database. create table employee( id number(10), name varchar2(100), salary number(10) % Employee,java This class contains 3 properties with constructors and setter and getters. package comjavatpoint; public class Employee { private int id; private String name; private float salary; //no-arg and parameterized constructors Ugetters and setters } EmployeeDao,java It contains one property jdbcTemplate and three methods saveEmployeeQ, updateEmployee and deleteEmployee(. tips: javatpeint.comisoring-Jdbe Tempate-tuloral sat0/10/2028 09:07 ‘Spring JdocTemplate Tutorial -javatpoint package comjavatpoint; import org springframeworkjdbc.core JdbcTemplate; public class EmployeeDao ( private JdbcTemplate jdbcTemplate; public void setIdbcTemplateUdbcTemplate jdbcTemplate) { this,jdbcTemplate = jdbcTemplate; ic public int saveEmployee(Employee e){ String query ="insert into employee values( “4e.getid(+","+e.getName(+","+e.getSalary()+")"; return jdbcTemplate.update(query); ) public int updateEmployee(Employee e){ String query="update employee set hame="+e.getName()+" where ii \salary="+e.getSalary()+ +egetldg+" "; return jdbcTemplate.update(query); } pul String que ic int deleteEmployee(Employee e){ ‘delete from employee where id return jdbcTemplate.update(query); applicationContext.xml The DriverManagerDataSource is used to contain the information about the database such as driver class name, connection URL, username and password, There are a property named datasource in the JdbcTemplate class of DriverManagerDataSource type. So, we need to provide the reference of DriverManagerDataSource object in the JdbcTemplate class for the datasource property. Here, we are using the JdbcTemplate object in the EmployeeDao class, so we are passing it by the setter method but you can use constructor also. tips: javatpeint.comispring-Jdbe Tempate-tuloral ont0/10/2028 09:07 ‘Spring JdocTemplate Tutorial -javatpoint
Test.java This class gets the bean from the applicationContext.xm! file and calls the saveEmployee() method, You can also call updateEmployee) and deleteEmployee() method by uncommenting the code as well package comjavatpoint; import org springframework.context ApplicationContext; import org springframework.context support.ClassPathXmlApplicationContext; public class Test ( nitpslwwwjavatpoint convspring-IdbeTemplate-tutorial am‘ortor029 09.07 Spring Jade Template Tuloal-javatpoint public static void main(Stringl] args) ( ApplicationContext ctx=new ClassPathXmiApplicationContext("applicationContext. xml"); EmployeeDao dao=(EmployeeDao)ctx.getBean(“edao"); int status=dao.saveEmployee(new Employee(102,"Amit",35000)); System.outprintin(status); /sint status=dao.updateEmployee(new Employee(102,"Sono0",15000)); System.out printin(status); ov /*Employee e=new Employee(); esetld(102); int status=dao.deleteEmployee(e); System.out printin(status);*/ download this example (developed using MyEclipse IDE) download this example (developed using Eclipse IDE) a) a) ‘outube For Videos Join Our Youtube Channel: Join Now tips: javatpeint.comispring-JdbeTemplate-tuloral ant0/10/2028 09:07 Feedback © Send your Feedback to feedback @javatpoint.com Help Others, Please Share Learn Latest Tutorials Splunk tutorial Splunk #Tumblr tutorial Tumblr DR Programming tutorial R Programming 2 Python Pillow tutorial Python Pillow Preparation PAptitude Aptitude SPSS tutorial SPSS React tutorial ReactlS PRIS tutorial RS: 2 Python Turtle ‘tutorial Python Turtle # Logical Reasoning tips: javatpeint.comisoring-Jdbe Tempate-tuloral i) Swagger tutorial Swagger #Regex tutorial Regex i) React Native tutorial React Native w#Keras tutorial Keras eiVerbal Ability Verbal Ability ‘Spring JdocTemplate Tutorial -javatpoint (#T-SQL tutorial ‘Transact-SQL. # Reinforcement earning tutorial Reinforcement Learning @® Python Design Patterns Python Design Patterns 2 Interview Questions gn0/10/2028 09:07 Reasoning. Trending Technologies 2 Artificial Intelligence Artificial Intelligence #Hadoop tutorial Hadoop #) Blockchain Tutorial Blockchain B.Tech / MCA (DBMS tutorial DBMS. 2 Computer Network tutorial ‘Computer Network Ethical Hacking Ethical Hacking LBAWS Tutorial AWS ww _ReactlS Tutorial ReactS Git Tutorial Git Data Structures tutorial Data Structures Compiler Design tutorial Compiler Design 2 Computer Graphics Tutorial tips: javatpeint.comispring-Jdbe Tempate-tuloral ‘Spring JdocTemplate Tutorial BD Selenium tutorial Selenium 1 Data Science Tutorial Data Science 2) Machine Learning Tutorial Machine Learning ADAA tutorial DAA BE Computer ‘Organization and Architecture Computer Organization 2) Software Engineering javatpoint Interview Questions 2 Company Interview Questions ‘Company Questions 2 Cloud Computing Cloud Computing #2 Angular7 Tutorial Angular 7 2 DevOps Tutorial DevOps 2 Operating System Operating System 2 Discrete Mathematics Tutorial Discrete Mathematics #html tutorial Web Technology sont0/10/2028 09:07 Cyber Security tutorial e2Java tutorial Java 2 Control Systems tutorial Control System Computer Graphics Automata ‘Tutorial Automata ez Ne Framework tutorial Net Data Mining Tutorial Data Mining ‘Spring JdocTemplate Tutorial -javatpoint Software Engineering i) C Language C++ tutorial tutorial cH C Programming leiPython tutorial = g}_—_List of Python Programs Programs 2 Data Warehouse Tutorial Data Warehouse tips: javatpeint.comisoring-Jdbe Tempate-tuloral wnt
You might also like
SRIMAN Spring Material
PDF
83% (6)
SRIMAN Spring Material
282 pages
Spring in Action
PDF
No ratings yet
Spring in Action
50 pages
CRUD Operation Using Spring Boot
PDF
No ratings yet
CRUD Operation Using Spring Boot
16 pages
Module 5 Assignment Java (MCA)
PDF
No ratings yet
Module 5 Assignment Java (MCA)
16 pages
Spring - Data - Mongo-REST
PDF
No ratings yet
Spring - Data - Mongo-REST
61 pages
Spring JDBC
PDF
No ratings yet
Spring JDBC
11 pages
3 Day 3
PDF
No ratings yet
3 Day 3
11 pages
SpringBoot Data-JPA Guide
PDF
100% (1)
SpringBoot Data-JPA Guide
44 pages
JPA and Hibernate in 10 Steps
PDF
No ratings yet
JPA and Hibernate in 10 Steps
10 pages
FSD Unit5
PDF
No ratings yet
FSD Unit5
8 pages
Sriman Sir New Spring Book PDF
PDF
No ratings yet
Sriman Sir New Spring Book PDF
282 pages
Spring JDBC
PDF
No ratings yet
Spring JDBC
10 pages
Spring Fundamental Training - Part7
PDF
No ratings yet
Spring Fundamental Training - Part7
13 pages
Spring JDBC
PDF
No ratings yet
Spring JDBC
101 pages
2 Day 2
PDF
No ratings yet
2 Day 2
22 pages
Spring JDBC Example
PDF
No ratings yet
Spring JDBC Example
4 pages
Spring JDBC
PDF
No ratings yet
Spring JDBC
3 pages
Spring ORM
PDF
No ratings yet
Spring ORM
5 pages
2023051
PDF
No ratings yet
2023051
30 pages
Sriman Sir New Spring Book PDF
PDF
No ratings yet
Sriman Sir New Spring Book PDF
282 pages
Introduction To Spring JDBC
PDF
No ratings yet
Introduction To Spring JDBC
11 pages
New Spring Sriman PDF
PDF
80% (5)
New Spring Sriman PDF
282 pages
Jpa MVC
PDF
No ratings yet
Jpa MVC
41 pages
4 Day 4
PDF
No ratings yet
4 Day 4
21 pages
Persistence With Spring
PDF
No ratings yet
Persistence With Spring
98 pages
Spring
PDF
No ratings yet
Spring
24 pages
Spring Slides
PDF
No ratings yet
Spring Slides
63 pages
Spring
PDF
No ratings yet
Spring
6 pages
Material
PDF
No ratings yet
Material
12 pages
Crud Operation Using REST & Spring Boot
PDF
No ratings yet
Crud Operation Using REST & Spring Boot
4 pages
W.T. Unit-Iv
PDF
No ratings yet
W.T. Unit-Iv
8 pages
Advanced Java (Module 5)
PDF
No ratings yet
Advanced Java (Module 5)
11 pages
Spring JDBC Example
PDF
No ratings yet
Spring JDBC Example
5 pages
SRIMAN Spring Material
PDF
No ratings yet
SRIMAN Spring Material
282 pages
Ajp Unit 5
PDF
No ratings yet
Ajp Unit 5
3 pages
6 - Spring-Boot 2
PDF
No ratings yet
6 - Spring-Boot 2
11 pages
Notas Spring Framework 1
PDF
No ratings yet
Notas Spring Framework 1
21 pages
Inserting Data Into Datbase s9
PDF
No ratings yet
Inserting Data Into Datbase s9
6 pages
Creating Spring Application in Eclipse IDE
PDF
No ratings yet
Creating Spring Application in Eclipse IDE
11 pages
Spring Boot
PDF
No ratings yet
Spring Boot
19 pages
S 1
PDF
No ratings yet
S 1
10 pages
Spring
PDF
No ratings yet
Spring
8 pages
Sriman Sir (Spring Ssprinted)
PDF
100% (1)
Sriman Sir (Spring Ssprinted)
216 pages
FSD SpringCore 18042022
PDF
No ratings yet
FSD SpringCore 18042022
8 pages
MVC Spring Application Setup:: Dependencies
PDF
No ratings yet
MVC Spring Application Setup:: Dependencies
9 pages
Shashwat Chauhan (Spring Boot Rest API CRUD)
PDF
No ratings yet
Shashwat Chauhan (Spring Boot Rest API CRUD)
20 pages
Q.7.Write A Spring Program For Autowiring by Using Bytype ? Pom - XML
PDF
No ratings yet
Q.7.Write A Spring Program For Autowiring by Using Bytype ? Pom - XML
18 pages
Spring JournalDev
PDF
No ratings yet
Spring JournalDev
12 pages
Spring Data Jpa Sample Code 2025
PDF
No ratings yet
Spring Data Jpa Sample Code 2025
12 pages
Persistence With Spring PDF
PDF
No ratings yet
Persistence With Spring PDF
98 pages
Integration Spring and Hibernate
PDF
No ratings yet
Integration Spring and Hibernate
16 pages
Spring Boot 033
PDF
No ratings yet
Spring Boot 033
10 pages
Spring MVC With JdbcTemplate Example
PDF
No ratings yet
Spring MVC With JdbcTemplate Example
12 pages
Spring JDBC
PDF
No ratings yet
Spring JDBC
17 pages
@spring Data Annotations
PDF
No ratings yet
@spring Data Annotations
7 pages
Spring Transaction Management
PDF
No ratings yet
Spring Transaction Management
25 pages
Spring JDBC Class Notes
PDF
No ratings yet
Spring JDBC Class Notes
7 pages
Most Imp Spring Interview QN and Ans
PDF
No ratings yet
Most Imp Spring Interview QN and Ans
15 pages
P 16
PDF
No ratings yet
P 16
19 pages
P 14
PDF
No ratings yet
P 14
11 pages
S 3
PDF
No ratings yet
S 3
12 pages
B 2
PDF
No ratings yet
B 2
8 pages
Z 12
PDF
No ratings yet
Z 12
10 pages
Z 32
PDF
No ratings yet
Z 32
9 pages
B 5
PDF
No ratings yet
B 5
6 pages
Z 9
PDF
No ratings yet
Z 9
8 pages
B 9
PDF
No ratings yet
B 9
7 pages
B 3
PDF
No ratings yet
B 3
12 pages
B 5
PDF
No ratings yet
B 5
12 pages
B 2
PDF
No ratings yet
B 2
12 pages
Z 18
PDF
No ratings yet
Z 18
7 pages
S 6
PDF
No ratings yet
S 6
11 pages
Z 14
PDF
No ratings yet
Z 14
9 pages
B 1
PDF
No ratings yet
B 1
9 pages
S 4
PDF
No ratings yet
S 4
8 pages
Sa
PDF
No ratings yet
Sa
8 pages
Z 31
PDF
No ratings yet
Z 31
7 pages
Z34
PDF
No ratings yet
Z34
7 pages
Z 26
PDF
No ratings yet
Z 26
7 pages
Z 30
PDF
No ratings yet
Z 30
7 pages
Z 24
PDF
No ratings yet
Z 24
7 pages
Z 27
PDF
No ratings yet
Z 27
7 pages
Z 17
PDF
No ratings yet
Z 17
7 pages
S 8
PDF
No ratings yet
S 8
7 pages
Z 19
PDF
No ratings yet
Z 19
6 pages
Z 16
PDF
No ratings yet
Z 16
6 pages
B 8
PDF
No ratings yet
B 8
6 pages
X 3
PDF
No ratings yet
X 3
5 pages