| |

VerySource

 Forgot password?
 Register
Search
Author: flypigzj

EJBQL condition query for help in EJB, LIST array

[Copy link]

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-29 16:15:01
| Show all posts
public List findExamScoreinterface(List userid){


      String connselect="select o from TCJExamScore o where o.userID IN(:userID)";
      Query query=em.createQuery(connselect);
      query.setParameter("userID",userid);
       return query.getResultList();
}
What's wrong in my writing, why can't I make it?
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-30 17:15:02
| Show all posts
/**
* DB 検索
*/
public void findUsers() {
    Query query;
    String namePattern = null;
    //Into the force されたユーザネーム means
    if (!user.getUserName().equals("")) {
        namePattern ='%' + user.getUserName() +'%';
    }
    //Look at it.
    if (user.getUserCode() == ""&&user.getUserName() == "") {query = em.createQuery("from User");
    }else if(user.getUserCode() != ""&&user.getUserName() == "") {
query = em.createQuery("from User where user_code = :code");
query.setParameter("code", user.getUserCode());
To
log.info(">>>ユーザコード検索");
}
else if (user.getUserCode() == ""&&user.getUserName() != "") {
To
query = em.createQuery("from User where user_name like :userName");
query.setParameter("userName", namePattern);
To
log.info(">>>ユーザ名検索");
To
}
else {

query = em.createQuery("from User where user_code = :code and user_name like :userName");
To
query.setParameter("code", user.getUserCode());
query.setParameter("userName", namePattern);
To
log.info(">>>ユーザコード・ユーザ名検索");

}
To
userList = query.getResultList();
log.info(">>>show userlist-#0", userList);
To
if (userList.isEmpty()) {
log.info(">>>ユーザリストが空");
return;
}
for(User u: userList) {
log.info(">>>show userList-#0 #1", u.getUserCode(), u.getUserName(), u.getPassword());
}
To
}
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-30 17:30:01
| Show all posts
Ha, every time it is sorted out, it will be sent out accidentally. Many of the previous ones are for processing the input query conditions, so there is no practical significance. You can refer to it yourself. You can delete log.info directly. , I used the JBOSS-SEAM framework to do it, ha ha
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-30 20:15:01
| Show all posts
query.setParameter("userID",userid);
In this sentence, userID corresponds to an attribute of an entity BEAN,
In fact, the corresponding should be a field in the database, it looks like we set
The database field type is not a list, right? There is no error when compiling this.
Errors can occur when actually running.
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-31 09:00:01
| Show all posts
I wrote the full search step in my program to death
   ArrayList<String> userCode = new ArrayList<String>();
   userCode.add("H0001");
   userCode.add("H0002");
   query = em.createQuery("from User where user_code IN(:userCode)");
   query.setParameter("userCode", userCode);
   userList = query.getResultList();
It's easy to use. I don’t know where the original owner’s error is. You can pass the userid to and
Print the result after execution to see if it is an error elsewhere.
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-8-2 07:45:01
| Show all posts
ArrayList<String> userCode = new ArrayList<String>();
       userCode.add("wanglijuan");
      userCode.add("H0002");
      Query query;
      try{
   query = em.createQuery("select o from Subject o where o.subjectid IN(:subjectid)");
   query.setParameter("subjectid", userCode);
      }
      catch(Exception e){
               throw new EJBException(e);
      }
   return query.getResultList()

According to your method, I can't make it to death if I write it directly, and I make a mistake.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list