氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          一種Java調用Sybase存儲過程實現取前N條數據的方法

          一.在Sybase中創建存儲過程如下:
          Sql代碼:  
          1. drop procedure getPageWiseData  
          2. go   
          3. create procedure getPageWiseData    
          4. (    
          5. @sqlStr varchar(8000),    
          6. @start int,    
          7. @limit int   
          8. )    
          9. as    
          10. DECLARE @dt varchar(10)    --生成臨時表的隨機數    
          11. BEGIN      
          12. --# variable to hold the first row number of the page.    
          13. SELECT @dt= substring(convert(varchar, rand()), 3, 10)    --一個字符型的隨機數    
          14.    
          15. SELECT @sqlStr = stuff(@sqlStr, 1, 7, 'select rownum=identity(12), ')    
          16. SELECT @sqlStr = stuff(@sqlStr, charindex(' FROM ', upper(@sqlStr)), 6 ,' into tempdb..Lining' + @dt + ' from ')    
          17. execute (@sqlStr)     
          18. --# select the data with the calculated range for first and last row on page.    
          19. select @sqlStr = 'select * from tempdb..Lining' + @dt + ' where rownum >= '+convert(varchar, @start)+' and rownum < '+convert(varchar, (@start+@limit))     
          20. execute (@sqlStr)      
          21. --刪除臨時表    
          22. SELECT @sqlStr = 'DROP TABLE tempdb..Lining'+@dt   
          23. EXECUTE (@sqlStr)     
          24. END  
          二.用jdts驅動調用Sybase數據庫
          原文參考自站長網:
          http://www.software8.co/wzjs/java/3541.html
          Java代碼:  
          1. public class JdbcSybaseProcedure {  
          2.  public static void main(String[] args) {  
          3.   Connection conn = null;  
          4.   CallableStatement cs = null;  
          5.   try {  
          6.    Class.forName("net.sourceforge.jtds.jdbc.Driver");  
          7.    conn = DriverManager.getConnection("jdbc:jtds:sybase://192.9.190.98:4100/inner_dbs", "emp", "empemp");  
          8.    //下面的意思要調用那個存儲過程,存儲過程名字是getPageWiseData;  
          9.    cs = conn.prepareCall("{call getPageWiseData(?,?,?)}");  
          10.    cs.setString(1, "select * from lps_mst order by pan");  
          11.    cs.setInt(21);  
          12.    cs.setInt(35);  
          13.    //執行存儲過程  
          14.    ResultSet rs = cs.executeQuery();  
          15.    while(rs.next()) {  
          16.     System.out.println(rs.getString("pan"));  
          17.    }  
          18.   } catch (Exception e) {  
          19.    e.printStackTrace();  
          20.   } finally {  
          21.    try {  
          22.     cs.close();  
          23.    } catch (SQLException e) {  
          24.     e.printStackTrace();  
          25.    }finally {  
          26.     cs = null;  
          27.    }  
          28.    try {  
          29.     conn.close();  
          30.    } catch (SQLException e) {  
          31.     e.printStackTrace();  
          32.    }finally {  
          33.     conn = null;  
          34.    }  
          35.   }  
          36.  }  
          37. }  

          posted on 2013-03-27 08:43 你爸是李剛 閱讀(2007) 評論(1)  編輯  收藏

          評論

          # re: 一種Java調用Sybase存儲過程實現取前N條數據的方法 2013-05-13 17:05 -_-

          tempdb..Lining7471702744 not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).

          請問下 報這個錯怎么解決  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2013年3月>
          242526272812
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 望奎县| 马鞍山市| 陕西省| 崇阳县| 嘉鱼县| 改则县| 江西省| 云龙县| 湾仔区| 丰宁| 永平县| 故城县| 怀安县| 陆河县| 商南县| 安顺市| 仲巴县| 德格县| 甘谷县| 云龙县| 漳平市| 鹿泉市| 三原县| 嘉禾县| 淮南市| 双鸭山市| 白沙| 衡阳市| 虎林市| 苗栗县| 资源县| 棋牌| 博罗县| 遵化市| 韶山市| 芦山县| 怀仁县| 绥中县| 民权县| 宣恩县| 乐至县|