日期:2014-05-16 浏览次数:20492 次
DBConnection.java
package com.accp.common; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DBConnection { public static final String REIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver"; public static final String URL="jdbc:sqlserver://127.0.0.1:1433;databasename=messageBoard"; public static String name="sa"; public static String pwd="123456"; public static Connection getcoConnection() { Connection con=null; try { Class.forName(REIVER); con=DriverManager.getConnection(URL, name,pwd); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return con; } public static void closeAll(ResultSet rs,Statement st,Connection con) { if(rs!=null) { try { rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(st!=null) { try { st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (con!=null) { try { con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
?