This example shares the Java connection MySQL database code for your reference. The specific content is as follows
//java connects MySQl database instance code package com.abc.dao;/*dkplus specializes in collecting and writing practical computer software tutorials, * Collect various software resources and computer peripherals, independently produce videos and ppt and audio WeChat official accounts, * Click to enter the dkplus official blog (java network programming http://dkplus.iteye.com), * Search for dkplus on WeChat to follow the official account to obtain massive computer peripheral resources. */import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.Statement;public class BaseDao { public Connection getConn() { Connection conn=null; try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String url="jdbc:mysql://127.0.0.1:3306/user"; try { conn=DriverManager.getConnection(url, "root", ""); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } public void closeAll(ResultSet rs,Statement stat,Connection conn) { if(rs!=null) try { rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(stat!=null) try { stat.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(conn!=null) try { conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.