java面向对象高级分层实例_BaseDao
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                java面向对象高级分层实例_BaseDao
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            package bdqn.studentSys.Dao;
/*** 數據庫幫助類* @author Administrator**/
import java.sql.*;
public class BaseDao {Connection conn=null;PreparedStatement ps=null;ResultSet rs=null;//連接數據庫public void getConnection(){try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}try {conn=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;databasename=mydb;User=sa;Password=171268");} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}//增刪改public int executeUpdate(String sql,Object[]prams) throws SQLException{int rel=0;getConnection();ps=conn.prepareStatement(sql);if(prams!=null){for (int i = 0; i < prams.length; i++) {ps.setObject(i+1, prams[i]);}}rel=ps.executeUpdate();return rel;}//查詢public ResultSet executeQurey(String sql,Object[]prams) throws SQLException{getConnection();ps=conn.prepareStatement(sql);if(prams!=null){for (int i = 0; i < prams.length; i++) {ps.setObject(i+1, prams[i]);}}rs=ps.executeQuery();return rs;}//關閉釋放資源public void closeAll(){if(rs!=null){try {rs.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(ps!=null){try {ps.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(conn!=null){try {conn.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}
                            
                        
                        
                        總結
以上是生活随笔為你收集整理的java面向对象高级分层实例_BaseDao的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: VTEX正在改变协同商务的游戏
- 下一篇: 电脑无法加载用户配置?
