How to connect eclipse to mysql
May 11, 2019 pm 01:55 PMConnection steps: 1. Create a project (My); 2. Right-click My and select "build Path"->"add external jars.."; 3. Find the jdbc storage directory and select "MySQL.jar", click "Open"; 4. Click apply and apply and close.
Preparation work: Download MySQL and jdbc, which I won’t go into here. Note that you may have downloaded MySQL, but not jdbc. Their downloads are separate, so you can first look at some of the steps at the end of this article to make sure you have downloaded jdbc. If you have not downloaded it, go to the official website to download it. It is only a few megabytes and very fast.
1. First open eclipse and create a new project "My". The specific operation is:
Click "File"----Click "new"----Click "java project" , get the page as shown below, fill in the project name in the project name, such as "My", and then click "finish"
2. At this time, on the left we can see that the project has been Created
Right-click "My"-"build path"-"configure build path"
Click the second "add external jars" in the zip code here in libraries, find the location where you downloaded jdbc and decompressed it, find the MySQL jar and open it
3. Click apply and apply and close
import java.sql.*; public class Jdbc { public static void main(String args[]) { try { Class.forName("com.mysql.jdbc.Driver"); //加载MYSQL JDBC驱动程序 //Class.forName("org.gjt.mm.mysql.Driver"); System.out.println("Success loading Mysql Driver!"); } catch (Exception e) { System.out.print("Error loading Mysql Driver!"); e.printStackTrace(); } try { Connection connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","java");//java这个空填写的是你自己设的密码 System.out.println("Success connect Mysql server!"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from user"); //user 为你表的名称,可以在MySQL命令行用show tables;显示 while (rs.next()) { System.out.println(rs.getString("name")); } } catch (Exception e) { System.out.print("get data error!"); e.printStackTrace(); } } }
The above is the detailed content of How to connect eclipse to mysql. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Why can't eclipse import the project?

How to adjust background color settings in Eclipse

Pro Guidance: Expert advice and steps on how to successfully install the Eclipse Lombok plug-in

What are the eclipse decompilation plug-ins?

Revealing solutions to Eclipse code running problems: helping you troubleshoot various running errors

Secret method and quick solution to solve Eclipse failure to start

How to customize shortcut key settings in Eclipse

Step-by-step guide to changing background color with Eclipse
