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

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 想煩請各位先進幫小弟指點迷津
wade960645





發文: 3
積分: 0
於 2011-11-23 17:44 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
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
synchronized static public DefaultTableModel create_sortable(String sql,String db){
    
    Statement stmt = null ;
    
    ResultSet rs = null ;
    
    DefaultTableModel tableModel = new DefaultTableModel ();
    
    Properties pro_language = ConfigManager.getLanguageConfig();
    
    ConnectionManager connection = new ConnectionManager();
    
    Connection conn = connection.openConnect(db);
    
    try{
      
      stmt = conn.createStatement();
      
      rs = stmt.executeQuery(sql);
      
      int length = rs.getMetaData().getColumnCount();
      
      String [] arry = new String[length];
      
      for(int i = 0; i<length;i++){
        
        String column = rs.getMetaData().getColumnName(i+1).substring(4);
        
        if(pro_language.getProperty(column)!=null){
          
          arry[i] = pro_language.getProperty(column);
          
        }else{
          
          arry[i] = column ;
        }
      }
      
      tableModel.setDataVector(null, arry);
      
      Object[] o = null;
      
      while(rs.next()){
        
        o= new Object[length];
        
        for(int i =0 ;i<length;i++){
          
        o[i] = rs.getObject(i+1);
        
        
        
        }
        tableModel.addRow;
      }
      
      TableModel sortable_model = setSortable(tableModel);
      
      rs.close();
      
      stmt.close();
      
      connection.closeConnect(conn);
      
      return (DefaultTableModel)sortable_model;       
    }catch(Exception e){
      
      e.printStackTrace();
    }finally{
      
      if(rs!=null){
        try{
          rs.close();
        }catch(Exception e){
          
        }
        
      }
      if(stmt!=null){
        try{
          stmt.close();
        }catch(Exception e){
          
        }
      }
    }
 
 return null;           
  }


-------------------------------------------------------------

小弟的疑問來自如以上程式碼紅色區塊,小弟不明白為何一個Methods會有兩個Return?而我將return (DefaultTableModel)sortable_model; 這段程式碼註解掉,編譯器竟也會過?那這樣回傳的不就是Null而非DefaultTableModel型態了,小弟不才,煩請各位先進指點迷津,盼此。在此先感謝各位大師了。


wade960645 edited on 2011-11-23 17:48
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
577 想煩請各位先進幫小弟指點迷津 wade960645 2250 2011-11-23 17:44
621 Re:想煩請各位先進幫小弟指點迷津 pclevin 126 2011-11-23 18:30
» JWorld@TW »  Java 新手區

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