zoukankan      html  css  js  c++  java
  • Ubuntu上Java连接mysql数据库

    首先,创建一个WEB工程

    然后,将mysql的jdbc驱动下载下来,然后放入该WEB工程的lib文件夹下面。

    接着,创建一个数据库User和相应的表user。

    然后,通过一下代码连接数据库

    String driver = "com.mysql.jdbc.Driver";

            // URL指向要访问的数据库名scutcs

            String url = "jdbc:mysql://localhost/User";

            // MySQL配置时的用户名

            String user = "root";

            // Java连接MySQL配置时的密码

            String password = "100963";

            try {

            // 加载驱动程序

            Class.forName(driver);

            // 连续数据库

            connection = (Connection) DriverManager.getConnection(url, user, password);

            if(!(connection==null))
              System.out.println("Succeeded connecting to the Database!");
            else
                System.out.println("Failed connecting to the Database!");
           }
            catch(Exception e){
                e.printStackTrace();
            }

    之后,在通过相应的代码对数据库进行操作。

  • 相关阅读:
    面试小结
    Everything工具使用
    记 · 工作一周年
    贝叶斯算法原理分析
    MySQL与Oracle主键Query性能测试结果
    K-meams文本聚类算法C++实现
    OPTICS光学算法
    页面添加内容后弹出框与跳转页面
    Webgrid参数格式
    页面2级分类
  • 原文地址:https://www.cnblogs.com/JulianJiang/p/3370944.html
Copyright © 2011-2022 走看看