vineet kaushik

Greenhorn
+ Follow
since Aug 05, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by vineet kaushik

Hi Guys,

Here I am trying to understand the real purpose of session configuration in Web.xml for session timeout.


<!-- Session Configuration -->
<session-config>
<session-timeout>60</session-timeout>
</session-config>

Now let me tell about my question..

my application is importing/uploading a .txt file and which is bound to take more than 1 hour Since there are millions of records to be imported.
But session gets timed out after 1 hour though my application is still importing that .txt file which is in progress.
As such application should not timeout as application is doing some task in background.

Thanks,
Vineet

Hi All,

If HttpServletRequest is an interface then how do we call the getSession() declared in this interface???

Thanks,
VIneet
8 years ago
Hi Guys,

Having used JdbcTemplate I was working on NamedParameterJdbcTemplate with queryForInt(sql,sqlParamSource) method and getting below error .

Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.dao.support.DataAccessUtils.requiredSingleResult(Ljava/util/Collection;)Ljava/lang/Object;
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:152)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:164)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForInt(NamedParameterJdbcTemplate.java:191)
at dao.EmpDaoImpl_new.getNoEmployee(EmpDaoImpl_new.java:46)
at main.EmpMainNamed.getNoEmployee(EmpMainNamed.java:27)
at main.EmpMainNamed.main(EmpMainNamed.java:23)


and Please see my code below..

mybeans.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">;
<beans>

<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="sys" />

</bean>

<bean id="empDao_new" class="dao.EmpDaoImpl_new">
<constructor-arg>
<ref local="datasource" />
</constructor-arg>
</bean>
</beans>

EmpDaoImpl_new.java


package dao;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import com.Interface.*;
import com.Model.Employee;;

public class EmpDaoImpl_new implements EmpDao{

NamedParameterJdbcTemplate namedParameterJdbcTemplate;

public EmpDaoImpl_new() {
// TODO Auto-generated constructor stub
}
public EmpDaoImpl_new(DataSource ds ) {
this.namedParameterJdbcTemplate=new NamedParameterJdbcTemplate(ds);
}

public Employee getEmpById(int eno) {
// TODO Auto-generated method stub
return null;
}
public int getNoEmployee(String first_name) {
String sql="select count(0) from employee where first_name= :firstName";
SqlParameterSource sqlParamSource=new MapSqlParameterSource("firstName",first_name);
int noEmployee=namedParameterJdbcTemplate.queryForInt(sql,sqlParamSource);
return noEmployee;
}
}

EmpMainNamed.java


package main;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

import com.Interface.EmpDao;

public class EmpMainNamed {

BeanFactory beanFactory;

EmpDao empDAO;

public EmpMainNamed() {

beanFactory = new XmlBeanFactory(new FileSystemResource("src/mybeans.xml"));
empDAO = (EmpDao) beanFactory.getBean("empDao_new");
}

public static void main(String[] args) {
EmpMainNamed obj = new EmpMainNamed();
obj.getNoEmployee("RAM");
}

public void getNoEmployee(String first_Name) {
int empCount = empDAO.getNoEmployee(first_Name);
System.out.println("Number of employees aginst " + first_Name + " is "
+ empCount);

}
}


EmpDao.java

package com.Interface;

import java.util.List;



public interface EmpDao {


public int getNoEmployee(String first_name);

}



NOte:- Datasource is NamedParameterJdbcTemplate is being pulled correctly. and It is generating error while invoking queryForInt(sql,sqlParamSource).

Quick response is deeply appreciated.

Thanks,
Vineet

8 years ago
Correct Mark,

Thanks for sharing your knowledge..

Thanks,
Vineet
8 years ago
Here is code to pull multiple rows using Rowmapper and jdbcTemplate.query(arg1,arg2).

Collection emp=jt.query("select * from employee", new RowMapper()
{
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Employee e=new Employee();
e.setFirstName(rs.getString("first_name"));
e.setLastName(rs.getString("last_name"));
e.setAge(rs.getInt("age"));
e.setEmail(rs.getString("email"));
e.setEmpno(rs.getInt("empno"));
return e;
}
});
8 years ago
I Guess, I have got the answer of my question .. I was using queryForObject(arg1,arg2,arg3) method of JDBC template instead of query(arg1,arg2,arg3) method of JDBC template.... RowMapper callback interface can pull multiple rows..

Please fell free to improve above mentioned answer.

Thanks,
Vineet
8 years ago
Hi Guys,

This is just to check RowMapper callback interface's mapRow(ResultSet rs, int rowNum) can pull only one row??/

Thanks,
Vineet
8 years ago
It helped to eradicate the confusion on Call back for me.. Thanks for sharing..
8 years ago
Hi Guys,

What i need to do, To have multiple struts-config.xml file in a single web application.

Thanks,
Vineet kaushik

10 years ago
HI Guys,

Does anyone know??? ,
how to change the name of web.xml file

Thanks,
Vineet
10 years ago
Hi Guys,

I want to access a resource(jsp file) outside of the web application.

e.g
I want to show http://localhost:8080/abc/jsp/1.jsp file in case my application(http://localhost:8088/xyz/2.jsp) shows any exception
I tried it in this way
<error-page>
<error-code>500</error-code>
<location>http://localhost:8080/abc/jsp/1.jsp</location>;
</error-page>


please help me .
Thanks,
Vineet kaushik
10 years ago