如何在Eclipse中使用MySql数据库 [英] how to use a MySql database within Eclipse

查看:386
本文介绍了如何在Eclipse中使用MySql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编程很陌生,所以请先忍受,如果起初我没有任何道理,请提前道歉...!

I am very new to programming, so please bear with me, and apologies in advance if at first I dont make sense...!

我正在做一个本科生编程项目,需要在Java程序中建立一些数据库.我正在使用eclipse(galilo)编写程序.我已经下载了一个连接器/J,但是还没有看到我应该如何使用它!

I am doing an undergrad programming project, and need to make some databases within a Java program. I am using eclipse (galilo) to write my program. I have downloaded a connector/J, but havent the foggiest how i should use it!

外面有人能给我循序渐进的方法吗?!

Anyone out there able to give me a step by step approach?!

非常感谢!

推荐答案

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

If you need a data explorer of some sort inside your eclipse, you can look at the links provided above or more specifically the plugin's documentation.

OTOH,如果您想知道如何使用JDBC连接到mysql数据库,则下面的代码示例对此进行了说明.

OTOH, if you want to know how you connect to a mysql database using JDBC, the below code sample explains it.

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();
        }

这篇关于如何在Eclipse中使用MySql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆