import java.sql.*;public class DbConnectionManager {/**
 * 此处插入方法描述。
 * 创建日期:(2003-3-26 15:28:16)
 * @param args java.lang.String[]
 */  public static Connection getConnection(String s){
Connection con = null;
String Error="";
try{
//加载oracle的驱动程序
//Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
//Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Class.forName("com.mysql.jdbc.Driver").newInstance();
// 主机名和端口 
//String url = "jdbc:oracle:thin:@10.128.0.8:1521:yofcdb";
//String url = "jdbc:oracle:thin:@10.128.0.10:1521:info21";
//String url = "jdbc:mysql://localhost/test";
String url = "jdbc:mysql://127.0.0.1/csepdi";
//建立连接
con = DriverManager.getConnection(url,"root","123456"); 
}catch(ClassNotFoundException cnfe){
Error = "ClassNotFoundException:Could not locate DB driver.";
//throw new ClassNotFoundException(Error);
System.err.println(Error);
}catch(SQLException cnfe){
Error = "SQLException:Could not connect to database.";
//throw new SQLException(Error);
System.err.println(Error);
}catch(Exception e){
Error = "Exception:An unknown error occurred while connecting to database.";
//throw new Exception(Error);
System.err.println(Error);
}
return con;
}
}
用连接池的例子!!