Newsletter |
Query Methods Of Spring JdbcTemplate With Examples
Let us see the query methods of spring JdbcTemplate…
- queryForInt()
- queryForLong()
- queryForObject()
- queryForList()
and 1 or 2 more but these are highly using methods, if you want i will give you the total query methods list.. 🙂 don’t fear nothing is there light..
queryForInt()
- Return type of queryForInt() method is int
Syntax:
int k = queryForInt(” static sql command “) ;&
int k = queryForInt(” dynamic sql command “, Object array);
- See we can pass either static,dynamic sql commands
- We used to execute inserting rows, deleting rows bla bla as its return type is integer
queryForLong()
- Return type of queryForLong() method is long
Syntax:
long k = queryForLong(” static sql command “) ;&
long k = queryForLong(” dynamic sql command “, Object array);
- See we can pass either static,dynamic sql commands
- We used to find sum of salaries of the employees bla bla., as its return type if long
queryForObject()
- Return type of queryForObject() method is object of Object class, we used to type cast later…
Ex:
Object o1 = queryForObject(” select sysdate from dual “, Date.class) ;
Object o2 = queryForObject(” select salary from emp”, Integer.class);
Object o3 = queryForObject(” select empName from emp”,String.class);Date d = (Date)o1;
Integer i = (Integer)o2;
String s = (String)o3;
- 🙂 see above 3 examples, i mean this queryForObject() will return the object of the type we called in the form of Object class object [ read this point slowly if its not clear 🙂 ]
- We used to find sum of salaries of the employees bla bla., as its return type if long
queryForList()
- Return type of queryForList() method is List object
Syntax:
List l = jt.queryForList(” static sql command “) ;&
List l = jt.queryForList(” dynamic sql command “, Object array);
- See we can pass either static,dynamic sql commands
So we are clear about all fundamentals for spring – JDBC let us start the applications 😉
You Might Also Like
::. About the Author .:: | ||
hi
good article ,i have a question
ArrayList chasssisCodesList;
try{
chasssisCodesList = (ArrayList) queryForList(
“select a,b,c from customer”, map);
}catch(Exception e){}
here chasssisCodesList is not initilized any where like new ArrayList(1);
if a called chasssisCodesList.size(),do it will throw nullPointer ???
i want to check user is exists inside database or not using spring mvc and rowmapper.please help me