java连接sqlserver数据库

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
 
public class ConnectionFactory 
{
 public static Connection getConnection() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException
 {
  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
  String url="jdbc:microsoft:sqlserver://localhost:1433;" + "databaseName=mydb;integratedSecurity=true;";
  //String url = "jdbc:sqlserver://localhost:1433;" + "databaseName=mydb;integratedSecurity=true;";
  String user="sa"; 
  String password="123"; 
  Connection conn= DriverManager.getConnection(url,user,password); 
  //return DriverManager.getConnection(url,user,password);
  System.out.println("连接很成功!");
 }
}
posted on 2012-05-25 09:39  无敌百搭  阅读(411)  评论(0编辑  收藏  举报