日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
DB2數(shù)據(jù)庫調(diào)用存儲過程的方法及實(shí)例介紹

上次我們介紹了DB2數(shù)據(jù)庫創(chuàng)建觸發(fā)器的實(shí)現(xiàn)過程,本文我們來介紹一下DB2數(shù)據(jù)庫存儲過程的調(diào)用,接下來就讓我們來一起了解一下這部分內(nèi)容吧。

創(chuàng)新互聯(lián)建站是一家專注于網(wǎng)站制作、網(wǎng)站建設(shè)與策劃設(shè)計(jì),湟源網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:湟源等地區(qū)。湟源做網(wǎng)站價(jià)格咨詢:028-86922220

一、對存儲過程的調(diào)用分三部分

1.連接(與數(shù)據(jù)庫建立連接)

 
 
 
  1. Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();
  2. Connection con=DriverManager.getConnection(url,user,password);

2.注冊輸出參數(shù)

 
 
 
  1. cs.registerOutParameter (3, Types.INTEGER);

3.調(diào)用存儲過程:

 
 
 
  1. CallableStatement cs=con.prepareCall("{call store_name(參數(shù),參數(shù),參數(shù))}");

二、調(diào)用舉例:

 
 
 
  1. import java.net.URL;
  2. import java.sql.*;
  3. class test2
  4. {
  5. public static void main(String args[])
  6. {
  7. String url = "jdbc:db2://wellhope/sample";
  8. String user="db2admin";
  9. String password="db2admin";
  10. try
  11. {
  12. Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();
  13. //與數(shù)據(jù)庫建立連接
  14. Connection con=DriverManager.getConnection(url,user,password);
  15. checkForWarning(con.getWarnings());
  16. DatabaseMetaData dma=con.getMetaData();
  17. String str="This is a string";
  18. //int hashcode=str.hashCode();
  19. //System.out.println("Hashcode   "+hashcode);
  20. //創(chuàng)建Statement對象,用于執(zhí)行SQL語句
  21. Statement stmt=con.createStatement();
  22. //創(chuàng)建CallableStatement對象,用于執(zhí)行存儲過程
  23. CallableStatement cs=con.prepareCall("{call PRO_YHDL1(?,?,?)}");
  24. //注冊輸出參數(shù)
  25. cs.registerOutParameter (3, Types.INTEGER);
  26. int result = 0;
  27. cs.setString(1,"123");
  28. cs.setString(2,"123");
  29. cs.execute();
  30. result = cs.getInt (3);
  31. dispResultSet(result);
  32. cs.close();
  33. con.close();
  34. }
  35. catch(SQLException ex)
  36. {
  37. System.out.println(" * * * SQLException caught * * * ");
  38. while(ex!=null)
  39. {
  40. System.out.println("SQLState: "+ex.getSQLState());
  41. System.out.println("Message: "+ex.getMessage());
  42. System.out.println("Vendor: "+ex.getErrorCode());
  43. exex=ex.getNextException();
  44. System.out.println("");
  45. }
  46. }   
  47. catch(java.lang.Exception ex)
  48. {    
  49. ex.printStackTrace();
  50. }
  51. }

三、存儲過程舉例:

Pro_yhdl1是一個(gè)存儲過程,它的功能是從數(shù)據(jù)庫表YHDL中取出PWD:

 
 
 
  1. import java.sql.*;                  
  2. public class Pro_yhdl1
  3. {
  4. public static void pro_yhdl1 ( String m_id,
  5. String m_pwd,
  6. int[] result ) throws SQLException, Exception
  7. {
  8. // Get connection to the database
  9. Connection con = DriverManager.getConnection("jdbc:default:connection");
  10. PreparedStatement stmt = null;
  11. ResultSet rs = null;
  12. String sql;
  13. String m_password="";
  14. sql = "SELECT"
  15. + "       DB2ADMIN.YHDL.PWD"
  16. + " FROM"
  17. + "    DB2ADMIN.YHDL"
  18. + " WHERE"
  19. + "    ("
  20. + "       ( "
  21. + "          DB2ADMIN.YHDL.ID = '"+m_id.trim()+"'"
  22. + "       )"
  23. + "    )";
  24. stmt = con.prepareStatement( sql );
  25. rs = stmt.executeQuery();
  26. // Access query results
  27. while (rs.next())
  28. {
  29. m_password=rs.getString(1);
  30. m_passwordm_password=m_password.trim();
  31. if (rs.wasNull())
  32. System.out.print("NULL");
  33. else
  34. System.out.print(m_password);
  35. }
  36. if(m_password.equals(m_pwd.trim()))
  37. {
  38. result[0] =1;
  39. }
  40. else
  41. {
  42. result[0] =0;
  43. }
  44. // close open resources
  45. if (rs != null) rs.close();
  46. if (stmt != null) stmt.close();
  47. if (con != null) con.close();
  48. // set return parameter
  49. //result[0] = result[0];
  50. }
  51. }

關(guān)于DB2數(shù)據(jù)庫調(diào)用存儲過程的知識就介紹到這里了,希望本次的介紹能夠?qū)δ兴鶐椭?/p>
新聞名稱:DB2數(shù)據(jù)庫調(diào)用存儲過程的方法及實(shí)例介紹
本文URL:http://m.5511xx.com/article/ccdghhi.html