2014-09-12 2 views
0

URL에서 여러 변수를 검색하려고하는데 특정 개체를 선택하기 위해 데이터베이스에 쿼리를 보낼 수는 있지만 첫 번째 개체를 선택하고 다른 개체는 null 인 것으로 보입니다.JSON URL에 여러 변수 가져 오기

@RequestMapping(value = "getGroup/{Name}/{StartDate}/{EndDate}/{Status_GroupID}", method = RequestMethod.GET) 
public @ResponseBody List<GroupsDetails> getGroupList(
     @PathVariable String Name, String StartDate, String EndDate, 
     Integer Status_GroupID) { 

    return musicStoreService.getGroupList(Name, StartDate, EndDate, Status_GroupID); 
} 

오류 내가 잡 오전 :

테이블은 그룹 이름과 행이됩니다
Hibernate: select groupsdeta0_.Status_GroupID as Status1_1_, groupsdeta0_.GroupsID as GroupsID1_,  groupsdeta0_.EndDate as EndDate1_, groupsdeta0_.Name as Name1_, groupsdeta0_.StartDate as StartDate1_ from Groups groupsdeta0_ where groupsdeta0_.Name=Gamma and (groupsdeta0_.StartDate is null) and (groupsdeta0_.EndDate is null) and (groupsdeta0_.Status_GroupID is null) 
Sep 12, 2014 2:41:40 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [SpringDispatcher] in context with path [/ATS] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query] with root cause 
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'Gamma' in 'where clause' 

:

업데이트 이름, STARTDATE, 종료 날짜, Status_GroupID 및 GroupsID을 :

I을 행 세부 정보를 제공하여 기본 키를 검색하려고하지만 작동하지 않습니다.

@Override 
public List<GroupsDetails> getGroupList(String Name, String StartDate, String EndDate, Integer Status_GroupID) { 
    SessionFactory sessionFactory=HibernateSessionManager.getSessionFactory(); 
    Session session=sessionFactory.getCurrentSession(); 
    Transaction transaction=session.beginTransaction(); 
    try{ 
    transaction.begin(); 
    @SuppressWarnings("unchecked") 
    List<GroupsDetails> groupList=session.createSQLQuery("FROM Groups WHERE Name=" + Name + " AND StartDate=" + StartDate + " AND EndDate=" + EndDate + " AND Status_GroupID=" + Status_GroupID).list(); 
    return groupList; 
    }finally{ 
    session.close(); 
    } 

}

그러나 내가 구문 오류를 볼 수없는, 심지어 그래도, 심하게 구문은 예외를 발생시킵니다. 오류 : 당신은 모든 매개 변수의 @PathVariable 뿅이 필요

Hibernate: FROM Groups WHERE Name=Gamma AND StartDate=01-06-2014 AND EndDate=01-09-2014 AND Status_GroupID=1 
Sep 12, 2014 3:35:51 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [SpringDispatcher] in context with path [/ATS] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query] with root cause 
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Groups WHERE Name=Gamma AND StartDate=01-06-2014 AND EndDate=01-09-2014 AND' at line 1 

답변

0

처럼 : Name=Gamma은 당신이 Parameters를 사용하여 Query를 만들 수 있습니다 또는 Name='Gamma'

해야한다 :

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to use near 
'FROM Groups WHERE Name=Gamma AND StartDate=01-06-2014 AND EndDate=01-09-2014 AND' at line 1 

명확 누락 따옴표 예를 들어, 것을 보여준다 예 :

query = sess.createSQLQuery("SELECT * FROM Groups 
     WHERE NAME=:name AND StartDate=:startDate AND EndDate=:endDate 
     AND Status_GroupID=:status_GroupID").addEntity(Groups.class); 

    query.setString("name", name); 
    query.setDate("startDate", StartDate); 
    query.setString("endDate", EndDate); 
    query.setString("status_GroupID", Status_GroupID); 


List<GroupsDetails> groupList = query.list(); 
0

.

오류 세부 사항에 따라
public @ResponseBody List<GroupsDetails> getGroupList(
     @PathVariable String Name, @PathVariable String StartDate, @PathVariable String EndDate, 
     @PathVariable Integer Status_GroupID) 
+0

고맙습니다,하지만 지금은 또 다른 문제가 있습니다. 가능한 한 그것을 보여 줄 수 있습니까? – Spinxas