首先当然要下载驱动,我用的是mysql-connector-java-5.0.4-bin.jar

public class ConnectionFactory {    
    
public static Connection getConnection(){
        Connection conn 
=null;        
        
try {
            Class.forName(
"com.mysql.jdbc.Driver");
            conn 
=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/st_storm?useUnicode=true&characterEncoding=utf-8","root""");
        }
 catch (ClassNotFoundException e) {
            System.out.println(
" No class " + " found error"); e.printStackTrace();
        }
 catch (SQLException e) {
            System.out.println(
"Failed to get connection :" +e.getMessage()); e.printStackTrace();
        }

        System.out.println(
"conn=="+conn);
        
return conn;
    }

st_storm是我要连接的库名