新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PreparedStatement使用之JDBC存儲過程調用的代碼實例
PreparedStatement使用方法JDBC存儲過程調用的代碼實例是本文我們主要要介紹的內(nèi)容,接下來就讓我們一起來了解一下下面的代碼實例吧。

代碼實例如下:
- package datebase;
- import java.sql.*;
- public class mypreparedstatement {
- private final String db_driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
- private final String url = "jdbc:sqlserver://localhost:1433;DatabaseName=ZC_NmSoft";
- public mypreparedstatement()
- {
- }
- public void query() throws SQLException{
- Connection conn = this.getconnection();
- //*********************************************查詢********************
- String strsql = "select * from ZC_Attendanceregister where AR_ID = ?";
- PreparedStatement pstmtq = conn.prepareStatement(strsql);
- pstmtq.setInt(1, 587);
- ResultSet rs = pstmtq.executeQuery();
- while(rs.next()){
- String fname = rs.getString("AR_AdmissionID");
- System.out.println("the fname is " + fname);
- }
- //************************************************刪除******************
- String strsqld= "delete from ZC_Attendanceregister where AR_ID = ?";
- PreparedStatement pstmtd = conn.prepareStatement(strsqld);
- pstmtd.setInt(1, 587);
- int dd = pstmtd.executeUpdate();
- //***********************************************添加*******************
- String strsqladd = "insert into ZC_Attendanceregister(AR_RegistrationDate,AR_AdmissionID,AR_Attendance,AR_Notes,AR_Mealssettlement) values(?,?,?,?,?)";
- PreparedStatement pstmta = conn.prepareStatement(strsqladd);
- pstmta.setString(1, "2010-07-26");
- pstmta.setString(2, "260");
- pstmta.setString(3, "出勤");
- pstmta.setString(4, "備注");
- pstmta.setString(5, "應該繳費");
- int add = pstmta.executeUpdate();
- rs.close();
- pstmta.close();
- conn.close();
- }
- private Connection getconnection() throws SQLException{
- // class.
- Connection conn = null;
- try {
- Class.forName(db_driver);
- conn = DriverManager.getConnection(url,"sa","sa");
- }
- catch (ClassNotFoundException ex) {}
- return conn;
- }
- //main 測試
- public static void main(String[] args) throws SQLException {
- mypreparedstatement jdbctest1 = new mypreparedstatement();
- jdbctest1.query();
- }
- }
以上就是PreparedStatement使用之JDBC存儲過程調用的代碼實例,本文我們就介紹到這里了,希望本次的介紹能夠對您有所收獲!
【編輯推薦】
- SQL Server數(shù)據(jù)庫多表關聯(lián)匯總查詢的問題解決
- 設置SQL Server數(shù)據(jù)庫AWE機制使其支持大內(nèi)存
- SQL Server 2008數(shù)據(jù)庫被標記為可疑的解決方法
- SQL Server數(shù)據(jù)庫中FOR XML AUTO的使用詳解續(xù)
- SQL Server使用UNION代替OR提升查詢性能的實例
名稱欄目:PreparedStatement使用之JDBC存儲過程調用的代碼實例
本文路徑:http://www.dlmjj.cn/article/djoihpc.html


咨詢
建站咨詢
