When linking a remote database, you need to modify the URL you obtained from the link. This article shares the specific code for your reference. The specific content is as follows
package com.test;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;/** * jdbc link remote database (the company's 176 library) operation* * @Author: Zhang Haoliang* @Date: June 16, 2016 at 10:56:43 am */public class JdbcTest { public static void main(String[] args) throws SQLException { // Register driver DriverManager.registerDriver(new com.mysql.jdbc.Driver()); // Get the link Connection conn = DriverManager.getConnection("jdbc:mysql://10.27.104.176:3306/mydatabase", "root", "mysql"); // Get the object of the operating database sql statement Statement st = conn.createStatement(); // Execute ResultSet rs = st.executeQuery("select * from apparatus_info"); // Get the result set while (rs.next()) { System.out.println(rs.getObject(1)); System.out.println(rs.getObject(2)); } // Close the resource rs.close(); st.close(); conn.close(); }}The above is all about this article, I hope it will be helpful to everyone's learning.