package com.gaowj.util;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.*;
public class ConnectionFactory {

  public static Connection getConn(){
	  String user="sa";
 	    String pass="FTMISWJI0818";
 	    String url="jdbc:sqlserver://localhost:331;DatabaseName=xcgm";
 	    Connection conn=null;
  	try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn=DriverManager.getConnection(url, user, pass);
		} catch (ClassNotFoundException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return conn;
  }
  public static Connection getConn(String inurl,String ls_database,String password){
	  String user="sa";
 	    String pass=password;
 	    String url="jdbc:sqlserver://"+inurl+";DatabaseName="+ls_database;
 	    Connection conn=null;
  	try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn=DriverManager.getConnection(url, user, pass);
		} catch (ClassNotFoundException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return conn;
  }
  
  public static void main(String[] a){
//	  Connection conn=getConn();
//	  Statement st;
//	  ResultSet rs;
//	  try {
//		st=conn.createStatement();
//		rs=st.executeQuery("select * from zy_com_pm");
//		while(rs.next()){
//			System.out.println(rs.getString(1));
//		}
//		rs.close();
//		st.close();
//	} catch (SQLException e) {
//		// TODO Auto-generated catch block
//		e.printStackTrace();
//	}
//	  try {
//		  InetAddress[] addresses=InetAddress.getAllByName("www.baidu.com");
//          
//		  for(InetAddress addr:addresses)
//
//		  {
//          
//		  System.out.println(addr);
//
//		  }
//
//	} catch (UnknownHostException e) {
//		// TODO Auto-generated catch block
//		e.printStackTrace();
//	}
  }
}
