日期:2014-05-16 浏览次数:20472 次
package com.ysu.db.conn; import java.sql.*; public class Connection { public java.sql.Connection getConnection(){ java.sql.Connection conn = null; String JDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL数据库引擎 String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=tempdb";//数据源 try { Class.forName(JDriver); conn = DriverManager.getConnection(url, "sa", "sa"); } catch (Exception e) { e.printStackTrace(); // TODO: handle exception } return conn; } public static void main(String[] args) { Connection conn = new Connection(); java.sql.Connection con = conn.getConnection(); System.out.println(con); java.sql.Connection con1 = conn.getConnection(); System.out.println(con1); } }