链接MySQL的代码片断

public class DB {
     public static Connection getConn() {
           Connection conn = null;
           try {
                   Class.forName("com.mysql.jdbc.Driver");
                    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs", "root" , "root");
          } catch (ClassNotFoundException e) {
                      e.printStackTrace();
          } catch (SQLException e) {
                  e.printStackTrace();
          }
          return conn;
   }

}

你可能感兴趣的:(JAVA)