JDBC连接数据库

public class DbUtil {
    public static Connection getConnection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            try {
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
                return conn;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            System.out.println("未成功加载类");
        }
        return null;
    }
posted @ 2017-05-23 09:20  Mu_gua  阅读(108)  评论(0编辑  收藏  举报