文件名称:简单财务管理系统 java sql 数据库
文件大小:122KB
文件格式:DOC
更新时间:2014-05-01 13:00:23
财务管理系统
import java.sql.*; public class DataBaseConnection { static{ //2005 //String DBDRIVER="com.microsoft.jdbc.sqlserver.SQLServerDriver";//2000 } public static Connection getConn(){ String DBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver"; String DBURL="jdbc:sqlserver://localhost:1433;DatabaseName=cwgl"; Connection conn=null; try { Class.forName(DBDRIVER); conn=DriverManager.getConnection(DBURL,"sa","1"); } catch (Exception e) { e.printStackTrace(); } return conn; } public static void closeConn(Connection conn){ try { conn.close(); conn=null; } catch (SQLException e) { e.printStackTrace(); } } public static Statement getStmt(Connection conn){ Statement stmt=null; try { stmt=conn.createStatement(); } catch (SQLException e) { e.printStackTrace(); } return stmt; } public static void closeStmt(Statement stmt){ try { stmt.close(); stmt=null; } catch (SQLException e) { e.printStackTrace(); } } public static PreparedStatement getpStmt(Connection conn,String sql){ PreparedStatement pStmt=null; try { pStmt=conn.prepareStatement(sql); } catch (SQLException e) { e.printStackTrace(); } return pStmt; } public static void closePstmt(Statement pstmt){ try { pstmt.close(); pstmt=null; } catch (SQLException e) { e.printStackTrace(); } } public static ResultSet getRs(Statement stmt,String sql){ ResultSet rs=null; try { rs=stmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } return rs; } public static void closeRs(ResultSet rs){ try { rs.close(); rs=null; } catch (SQLException e) { e.printStackTrace(); } } }