1. public static Connection getConnection(){  
  2.           
  3.         //或者Class.forName("com.mysql.jdbc.Driver");  
  4.         String url ="jdbc:mysql://localhost/test?user=admin&password=&useUnicode=true&characterEncoding=utf-8";   
  5.         //myDB为数据库名   
  6.         Connection conn= null;  
  7.         try{  
  8.             Class.forName("org.gjt.mm.mysql.Driver").newInstance();   
  9.             conn = (Connection) DriverManager.getConnection(url);     
  10.         }catch(Exception e){  
  11.             e.printStackTrace();  
  12.         }  
  13.         return conn;  
  14.     }