日期:2014-05-20 浏览次数:20755 次
import java.sql.*; public class Test { public static void main(String[] srg) { String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动 String dbURL = "jdbc:sqlserver://127.0.0.1:1434;databaseName=geniusclub"; //连接服务器和数据库geniusclub String userName = "sa"; //默认用户名 String userPwd = "wuyingjielao2"; //密码 Connection dbConn; try { Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL,userName,userPwd); System.out.println("OK"); System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful! } catch (Exception e) { e.printStackTrace(); } }