Steps to connect myeclipse to navicat:
1. Install mysql
2. Install myeclipse
3. Install mysql visual interface Navicat
4. Download JDBC driver Download address https://dev.mysql.com/downloads/connector/j/
5 .Configure the connection (key point)
1> Place the JDBC driver in the lib package under the new project (if there is no such folder, create it yourself), and then set it into the environment (right-click the jar file Then Build Path).
2>Open myeclipse-Window-perspective-Open Perspective-Myeclipse Database Explorer.
Related recommendations: "Navicat for mysql graphic tutorial"
3> After opening it, right-click on the blank version on the right side - New, and the following screen will appear requiring configuration information.
4> The configuration information is as follows:
(Note two points: 1.jdbc:mysql://
Then Finish if the Test Driver is successful.
5>Write java code to access the database.
public class DBUtil { private static final String URL="jdbc:mysql://127.0.0.1:3306/testdatabase"; private static final String USER="root"; private static final String PASSWORD=""; public static void main(String[] args) throws Exception { // TODO Auto-generated method stub //1.加载驱动程序 Class.forName("com.mysql.jdbc.Driver"); //2.获得数据库连接 Connection conn=DriverManager.getConnection(URL, USER, PASSWORD); //3.通过数据库的连接操作数据库,实现增删改查 Statement stmt = conn.createStatement(); ResultSet rs=stmt.executeQuery("select user_name,age from goddess where id=1"); while(rs.next()){ System.out.print(rs.getString("user_name")+","+rs.getInt("age")); } } }
The database is as shown in the figure:
Finally, the java code was successfully run.
The above is the detailed content of How to connect myeclipse to navicat. For more information, please follow other related articles on the PHP Chinese website!