JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Object Relational Mapping  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 hibernate查詢mysql資料庫,:=符號沒辦法執行
supercygnus





發文: 25
積分: 0
於 2014-01-03 18:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
使用SQL語法用hibernate做查詢
以下是SQL語法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public List getMessageList(){
    System.out.println("Go!!!");
    int usernumber=(int) this.getSession().get("user");
    int begin=(this.getCurrentPage()-1)*this.getPageSpan();
    int end=this.getCurrentPage()*this.getPageSpan();
    String sql="select row_number,msgnumber,fromuser,msginfo,msgtime from "+
        "(select @row_num \\:= ifnull(@row_num,0) + 1 as row_number,msgnumber,fromuser,msginfo,msgtime from "+
        "(select oa_message.message_number as msgnumber,oa_user.user_realname as fromuser,oa_message.message_info as msginfo,date_format(oa_message.message_time,'%Y-%m-%d-%T') as msgtime "+
        "from oa_message inner join oa_user on "+
        "oa_message.message_fromuser=oa_user.user_number where oa_message.message_touser='200802' "+
        "order by oa_message.message_time desc) as A) as B";
    
    System.out.println(sql);
    List list=this.searchDB.getArrayList(sql);
    System.out.println("Gokkkk!!!");
    List fileList=new ArrayList();
    
    //System.out.println(((SendMsg)list.get(0)).getMsgContent());
    
    
//    for(int i=0;i<list.size();i++){
//      Object[] obj=(Object[]) list.get(i);
//      SendMsg msg=new SendMsg((int)obj[1],(String)obj[2],(String)obj[3],(String)obj[4]);
//      fileList.add(msg);
//    }
    
    System.out.println("Go3!!!");
    return fileList;
  }


1
2
3
4
5
6
7
8
public List getArrayList(String sql){
    Session session=sf.openSession();
    Query query=session.createSQLQuery(sql);
    List list=query.list();
    session.close();
    System.out.println("hello!!");
    return list;
  }


好像是因為select @row_num \\:= ifnull(@row_num,0) + 1 as row_number
:=這個符號會造成無法查詢

google了好久,解法大多是從:=前面加上跳脫字元\\

不會我加了之後還是沒辦法正常查詢
到底要怎麼辦呢~?


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
779 hibernate查詢mysql資料庫,:=符號沒辦法執行 supercygnus 1728 2014-01-03 18:22
» JWorld@TW »  Object Relational Mapping

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8