JDBC Connection for MySQL8.0 under Eclipse

Source: Internet
Author: User

Drive jar Package Download: Link: https://pan.baidu.com/s/1CELkAMoDAzzclKhAa5h7lg Password: XVLX

First create a new project and drag the MySQL8.0 drive jar package into the project.

Right-click the jar package, configure the build path for the jar package, and select Add directly to the build path.

This is done after the configuration:

Next, query the Country table in MySQL's own world library with JDBC, and output the names of 239 countries

Import Java.sql.connection;import java.sql.drivermanager;import java.sql.resultset;import java.sql.Statement; public class Main {public static void main (string[] args) {String db_driver = "Com.mysql.cj.jdbc.Driver"; String Db_url = "Jdbc:mysql://localhost:3306?usessl=false&servertimezone=asia/shanghai"; String db_username = "root"; String Db_password = "123456"; try {class.forname (db_driver); Connection Connection = drivermanager.getconnection (Db_url, Db_username, Db_password); Statement Statement = Connection.createstatement (); Statement.execute ("use"); ResultSet ResultSet = Statement.executequery ("SELECT * from ' Country '"), while (Resultset.next ()) {System.out.println ( Resultset.getstring ("Name"));} Resultset.close (); Statement.close (); Connection.close ();} catch (Exception e) {e.printstacktrace ();}}}

It is important to note that the MySQL8.0 and the lower versions are different: Db_driver to write Com.mysql.cj.jdbc.Driver, and to add UseSSL and Servertimezone after Db_url

JDBC Connection for MySQL8.0 under Eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.