java连接sqlserver数据库
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
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);
{
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("连接很成功!");
}
}
}
}