加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何在Eclipse中使用MySql数据库

发布时间:2020-12-15 08:32:44 所属栏目:Java 来源:网络整理
导读:我是编程新手,所以请耐心等待,如果一开始我没有意义,请提前道歉……! 我正在做一个本科编程项目,需要在Java程序中创建一些数据库.我正在使用eclipse(galilo)来编写我的程序.我已经下载了一个连接器/ J,但我不应该使用它最模糊! 那里的任何人都能够一步一步
我是编程新手,所以请耐心等待,如果一开始我没有意义,请提前道歉……!

我正在做一个本科编程项目,需要在Java程序中创建一些数据库.我正在使用eclipse(galilo)来编写我的程序.我已经下载了一个连接器/ J,但我不应该使用它最模糊!

那里的任何人都能够一步一步地给我一个方法吗?!

非常感谢!

解决方法

如果你需要在eclipse中使用某种数据浏览器,你可以查看上面提供的链接,或者更具体地说是插件的文档.

OTOH,如果你想知道如何使用JDBC连接到mysql数据库,下面的代码示例解释了它.

Connection connection = null;
        try {
            //Loading the JDBC driver for MySql
            Class.forName("com.mysql.jdbc.Driver");

            //Getting a connection to the database. Change the URL parameters
            connection = DriverManager.getConnection("jdbc:mysql://Server/Schema","username","password");

            //Creating a statement object
            Statement stmt = connection.createStatement();

            //Executing the query and getting the result set
            ResultSet rs = stmt.executeQuery("select * from item");

            //Iterating the resultset and printing the 3rd column
            while (rs.next()) {
                System.out.println(rs.getString(3));
            }
            //close the resultset,statement and connection.
            rs.close();
            stmt.close();
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读