Spring Create and Getting Placeholders from Bean Properties

Now we are going to see How to give values as properties to sql in spring, using BeanPropertySqlParameterSource and update method. Lets see an example of that. Offers.java jdbc.properties beans.xml OffersDao.java App.java output: Offer [id=3, name=Sue, email=sue@nowhereatall.com, text=PHP coding] Offer [id=4, name=krishna, email=balakrishna.pendyala12@gmail.com, text=this is my new offer] Note: if we run the program again the id will be automatically incremented.   If you found an error, highlight it and press Shift + Enter or click here to inform us.

Read more

Spring Executing Update Statements

This post is about executing update statements in sql in Spring, this is pretty straight forward the jdbcTemplate have a method called update we can use those to run sql level update of our database we already have a sample data in Offers table in database jdbc.properties Offers.java beans.xml OffersDao.java App.java output: Offer [id=1, name=Bob, email=bob@nowhereatall.com, text=I will write Java for you] Offer [id=3, name=Sue, email=sue@nowhereatall.com, text=PHP coding] If you found an error, highlight it and press Shift + Enter or click here to inform us.

Read more

Spring Using Named Parameters

  In this post we are going to see how to query with dynamic input for specific rows, rather than query the entire database. Offer.java jdbc.properties beans.xml OffersDao.java App.java output: Offer [id=1, name=Bob, email=bob@nowhereatall.com, text=I will write Java for you] Offer [id=2, name=Mike, email=mike@nowhereatall.com, text=Web design, very cheap] Offer [id=3, name=Sue, email=sue@nowhereatall.com, text=PHP coding] //this is the output of named parameter Should be Mike: Offer [id=2, name=Mike, email=mike@nowhereatall.com, text=Web design, very cheap] If you found an error, highlight it and press Shift + Enter or click here to inform us.

Read more

Spring Database Exceptions

Exceptions are common in any java based application, exceptions will follow a hierarchy before breaking the compiler. In spring there is a parent class to handle all types of exceptions which is called DataAccessException. We can handle all types of exception using this class. If you want to handle specific exception with some child class there are many child exception classes for every breaking operation. Lets have an example. lets take code from previous example. What happen in the below code is we defined a parent exception “DataAccessException” which handles every exception type. we also catched “CannotGetJdbcConnectionException” which only catches

Read more

Spring-Querying-Using-Jdbc-Template

In this post we gonna see Querying database in Spring using jdbcTemplate. Before starting every thing just add these dependencies to your maven project. pom.xml Now we have a create Offers table in backend which is stored in mysql database and we inserted some sample data. Offers.sql Below we have an Offers.java which takes values and we will return toString() when anyone called object. Offer.java So, Now we are going to Configure Connection pooling with Apache DBCP. The concept of connection pooling is simple, what we do is we just configure the connections only once for application level, because Creating a

Read more

Spring Reading Property Files

Properties files are files which stores information about some external details like data base connection user and password details. The properties file should end with .properties extension. Lets have an example which takes values from properties file and displays here. Jdbc.properties Robot.java beans.xml App.java output: root: letmein If you found an error, highlight it and press Shift + Enter or click here to inform us.

Read more