Java – how to use MySQL database in eclipse

I am a novice programmer, so please wait patiently. If I have no meaning at the beginning, please apologize in advance!

I am working on an undergraduate programming project and need to create some databases in Java programs I am using eclipse (Galileo) to write my program I've downloaded a connector / J, but I shouldn't use it the most fuzzy!

Can anyone there give me a way step by step?!

Thank you.

Solution

If you need to use some kind of data browser in eclipse, you can check the links provided above, or more specifically, the plug-in documentation

Otoh, if you want to know how to connect to MySQL database using JDBC, the following code example 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();
        }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>