How to use MySql database in Eclipse

I am very new to programming, so please carry me and apologize in advance if at first I don't make sense ...!

I am running a by-law programming project and have to do some databases as part of a Java program. I use eclipse (galilo) to write my program. I downloaded the / J connector, but I don’t know how I should use it!

Can anyone give me a step by step ?!

Many thanks!

+3
source share
2 answers

If you need any data explorer inside your eclipse, you can see the links above or, more specifically, the plugin documentation.

OTOH, , mysql JDBC, .

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

Source: https://habr.com/ru/post/1737207/


All Articles