ConnectionFactory.java 1.92 KB
Newer Older
罗绍泽 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
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();
//	}
  }
}