package dataBase;import ;import ;import ;import ;//import ;import ;import ;import ;public class DBHelper { private Connection con; private PreparedStatement pstmt; private ResultSet rs; //静态语句块,加载驱动 static { try { (""); } catch (ClassNotFoundException e) { (); } } public ArrayList findBySql(String sql, ArrayList params, Class> c) { con = (); try { pstmt=(sql); doParams(pstmt, params); rs=(); while(()){ /**************************************************/ } } catch (SQLException e) { // TODO Auto-generated catch block (); } return List; } //连接数据库 public Connection getCon() { try { con = ( "jdbc:sqlserver://;databaseName=数据库名", "连接数据库名", "密码"); } catch (SQLException e) { (); } return con; } //关闭所有连接 public void closeAll(ResultSet rs, PreparedStatement pstmt, Connection con) { if (rs != null) { try { (); } catch (SQLException e) { (); } } if (pstmt != null) { try { (); } catch (SQLException e) { (); } } if (con != null) { try { (); } catch (SQLException e) { (); } } } //对数据进行增、删、改 // insert into xx values(?,?); params={"张三","a"}; public void doUpdate(String sql, List params) { con = (); try { pstmt = (sql); doParams(pstmt, params); (); } catch (SQLException e) { (); } finally { closeAll(null, pstmt, con); } } public void doParams(PreparedStatement pstmt, List params) throws SQLException { if (pstmt != null && params != null && () > 0) { for (int i = 0; i < (); i++) { (i + 1, (i)); } } }}