日期:2014-05-20 浏览次数:20890 次
public class Test { private static Logger logger = Logger.getLogger(Test.class.getName()); public static void main(String[] args){ Connection conn = null; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { logger.error(e); } try{ conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName = Stu", "sa", "123"); System.out.println("建立连接成功"); }catch(SQLException e){ logger.error(e); }finally{ try{ if(null!=conn){ conn.close(); System.out.println("关闭连接成功"); } }catch(SQLException e){ logger.error(e); } } } }