Rohit Bajaj
asked on
wrong query string getting picked up java spring
HI,
I have a following file :
The DBTemplate.java file is as follows :
Even thought the query written in executeQuery is :
select * from extreme_search_param limit 0,5"
When i start the spring java application in debug mode and debug the
public ResultSet executeQuery (String sql) function
I see sql = select * from extreme_search_param
in debugger eclipse mode
What could be the reason for this ?
Thanks
I have a following file :
package com.yatra.extremesearch.dao.impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import com.yatra.extremesearch.dao.ParamDao;
import com.yatra.extremesearch.model.ExtremeSearchParam;
import com.yatra.extremesearch.DBTemplate.DBTemplate;
@Repository
public class ParamDaoImpl implements ParamDao {
@Autowired @Qualifier("yatraDB") DBTemplate yatraDB;
@Override
public List<ExtremeSearchParam> getReqParams() throws SQLException
{
List<ExtremeSearchParam> reqParams = new ArrayList<ExtremeSearchParam>();
ResultSet rs = yatraDB.executeQuery("select * from extreme_search_param limit 0,5");
while (rs.next()) {
ExtremeSearchParam param = new ExtremeSearchParam();
param.setOrigin(rs.getString("origin"));
param.setDest(rs.getString("destination"));
param.setMinDays(rs.getInt("min_dep_days"));
param.setMaxDays(rs.getInt("max_dep_days"));
param.setMinStay(rs.getInt("min_stay"));
param.setMaxStay(rs.getInt("max_stay"));
param.setSearchType(rs.getString("search_type"));
param.setIsValid(rs.getString("is_valid"));
param.setSplit(rs.getInt("split"));
reqParams.add(param);
}
return reqParams;
}
}
The DBTemplate.java file is as follows :
package com.yatra.extremesearch.DBTemplate;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
public class DBTemplate{
private static final Logger logger = Logger.getLogger(DBTemplate.class);
DataSource dataSource;
public DBTemplate(DataSource dataSource) {
this.dataSource = dataSource;
}
public ResultSet executeQuery (String sql) {
ResultSet rs = null;
Connection conn =null;
try {
conn = dataSource.getConnection();
rs = conn.createStatement().executeQuery(sql);
} catch (SQLException e) {
logger.error(e.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
Connection conn =null;
try {
conn = dataSource.getConnection();
conn.createStatement().executeUpdate(sql);
} catch (SQLException e) {
logger.error(e.getMessage());
}
finally{
if(conn!=null)
try {
conn.close();
} catch (SQLException e) {
logger.error(e.getMessage());
}
}
}
public void loadInfile(String dumpFile, String table){
Connection conn =null;
PreparedStatement ptmt = null;
String sql = "LOAD DATA LOCAL INFILE '"+ dumpFile.replace("\\", "\\\\") +
"' REPLACE INTO TABLE "+ table
+" FIELDS TERMINATED BY '\\t' LINES TERMINATED BY '\\n'"+
" (origin, destination, price, dep_date, arrival_date, supplier, search_type)";
try {
conn = dataSource.getConnection();
ptmt = conn.prepareStatement(sql);
ptmt.executeQuery();
} catch (SQLException e) {
logger.error(e.getMessage());
}
finally{
if(conn!=null)
try {
ptmt.close();
conn.close();
} catch (SQLException e) {
logger.error(e.getMessage());
}
}
}
}
Even thought the query written in executeQuery is :
select * from extreme_search_param limit 0,5"
When i start the spring java application in debug mode and debug the
public ResultSet executeQuery (String sql) function
I see sql = select * from extreme_search_param
in debugger eclipse mode
What could be the reason for this ?
Thanks
ASKER
result is also more.
ASKER
Does eclipse maintains an internal cache of some kind ?
Similar thing happened to me before also but i couldn't get the reason for it.
Restarting eclipse also didnt resolve the isse. But when i restarted my system things worked sanely...
Similar thing happened to me before also but i couldn't get the reason for it.
Restarting eclipse also didnt resolve the isse. But when i restarted my system things worked sanely...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This should not be possible. But if you are getting correct result then there might be issue with eclipse.
Please check & update.