自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

PreparedStatement使用之JDBC存儲(chǔ)過程調(diào)用的代碼實(shí)例

數(shù)據(jù)庫 SQL Server
本文我們主要介紹一個(gè)PreparedStatement使用方法JDBC存儲(chǔ)過程調(diào)用的代碼實(shí)例,希望能夠?qū)δ兴鶐椭?/div>

PreparedStatement使用方法JDBC存儲(chǔ)過程調(diào)用的代碼實(shí)例是本文我們主要要介紹的內(nèi)容,接下來就讓我們一起來了解一下下面的代碼實(shí)例吧。

代碼實(shí)例如下:

  1. package datebase;  
  2.  
  3. import java.sql.*;     
  4.  
  5. public class mypreparedstatement {      
  6. private final String db_driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";      
  7. private final String url = "jdbc:sqlserver://localhost:1433;DatabaseName=ZC_NmSoft";      
  8. public mypreparedstatement()       
  9. {      
  10. }      
  11. public void query() throws SQLException{      
  12. Connection conn = this.getconnection();  
  13.  
  14. //*********************************************查詢********************  
  15. String strsql = "select * from ZC_Attendanceregister where AR_ID = ?";      
  16. PreparedStatement pstmtq = conn.prepareStatement(strsql);      
  17. pstmtq.setInt(1, 587);      
  18. ResultSet rs = pstmtq.executeQuery();      
  19. while(rs.next()){      
  20. String fname = rs.getString("AR_AdmissionID");  
  21. System.out.println("the fname is " + fname);      
  22. }  
  23.  
  24.  
  25. //************************************************刪除******************  
  26. String strsqld"delete from ZC_Attendanceregister where AR_ID = ?";  
  27. PreparedStatement pstmtd = conn.prepareStatement(strsqld);  
  28. pstmtd.setInt(1, 587);  
  29. int dd = pstmtd.executeUpdate();  
  30.  
  31.  
  32. //***********************************************添加*******************  
  33. String strsqladd = "insert into ZC_Attendanceregister(AR_RegistrationDate,AR_AdmissionID,AR_Attendance,AR_Notes,AR_Mealssettlement) values(?,?,?,?,?)";  
  34. PreparedStatement pstmta = conn.prepareStatement(strsqladd);  
  35. pstmta.setString(1, "2010-07-26");  
  36. pstmta.setString(2, "260");  
  37. pstmta.setString(3, "出勤");  
  38. pstmta.setString(4, "備注");  
  39. pstmta.setString(5, "應(yīng)該繳費(fèi)");  
  40.  
  41. int add = pstmta.executeUpdate();  
  42.  
  43. rs.close();      
  44. pstmta.close();      
  45. conn.close();      
  46. }  
  47.  
  48. private Connection getconnection() throws SQLException{      
  49. // class.      
  50. Connection conn = null;      
  51. try {      
  52.  Class.forName(db_driver);      
  53. conn = DriverManager.getConnection(url,"sa","sa");  
  54. }      
  55. catch (ClassNotFoundException ex) {}      
  56. return conn;      
  57. }  
  58. //main 測(cè)試      
  59. public static void main(String[] args) throws SQLException {      
  60.  mypreparedstatement jdbctest1 = new mypreparedstatement();      
  61.  jdbctest1.query();      
  62.  }  
  63. }    

 

以上就是PreparedStatement使用之JDBC存儲(chǔ)過程調(diào)用的代碼實(shí)例,本文我們就介紹到這里了,希望本次的介紹能夠?qū)δ兴斋@!

【編輯推薦】

  1. SQL Server數(shù)據(jù)庫多表關(guān)聯(lián)匯總查詢的問題解決
  2. 設(shè)置SQL Server數(shù)據(jù)庫AWE機(jī)制使其支持大內(nèi)存
  3. SQL Server 2008數(shù)據(jù)庫被標(biāo)記為可疑的解決方法
  4. SQL Server數(shù)據(jù)庫中FOR XML AUTO的使用詳解續(xù)
  5. SQL Server使用UNION代替OR提升查詢性能的實(shí)例
責(zé)任編輯:趙鵬 來源: CSDN博客
相關(guān)推薦

2011-08-23 13:14:05

JDBC帶輸出參數(shù)的存儲(chǔ)過程

2009-07-08 17:17:16

JDBC調(diào)用存儲(chǔ)過程

2009-07-22 15:58:34

JDBC調(diào)用Oracl

2011-08-25 09:31:43

JDBC調(diào)用Oracl

2009-06-22 11:04:00

Jdbc存儲(chǔ)過程

2010-11-16 14:30:32

Oracle存儲(chǔ)過程

2010-10-26 14:50:11

oracle存儲(chǔ)過程

2010-11-10 15:16:14

Sql Server分

2010-09-14 10:16:57

sql server

2009-07-17 13:54:51

JDBC存儲(chǔ)過程

2009-01-19 08:59:04

PHP調(diào)用MySQL存儲(chǔ)過程MySQLi擴(kuò)展

2021-05-13 07:58:05

JDBC接口PreparedSta

2011-08-22 10:15:39

數(shù)據(jù)庫存儲(chǔ)過程

2009-07-23 14:10:38

Hibernate J

2010-03-30 12:50:42

Oracle存儲(chǔ)

2009-06-17 10:33:17

Hibernate 存

2011-08-12 11:22:53

Oracle存儲(chǔ)過程Java

2011-08-16 16:59:58

PLSQL分頁存儲(chǔ)過程Java

2010-08-25 09:56:02

DB2存儲(chǔ)過程

2011-08-23 10:14:09

JDBC更新計(jì)數(shù)行調(diào)用存儲(chǔ)過程SQL Server
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)