import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
/**
*
* @author qyf
*
*/
public class IPv6JdbcUtil {
public static void main(String[] args) {
try {
boolean ipv6 = true;
testDb2Connection(ipv6);
testMySQLConnection(ipv6);
testOracleConnection(ipv6);
testSqlServerConnection(ipv6);
testSybaseConnection(ipv6);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* ipv4 Driver URL:
* jdbc:mysql://127.0.0.1:3306/database
* ipv6 Driver URL:
* jdbc:mysql://address=(protocol=tcp)(host=2001:470:23:13::6)(port=3306)/database
*
* Deiver package version 5.1.31 以上
*
* @throws ClassNotFoundException
* @throws SQLException
*
*/
public static void testMySQLConnection(boolean ipv6) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
String jdbcIpv4Url = "jdbc:mysql://127.0.0.1:3306/databaseName";
String jdbcIpv6Url = "jdbc:mysql://address=(protocol=tcp)(host=2001:470:23:13::6)(port=3
java使用jdbc ipv6方式连接数据库
最新推荐文章于 2024-06-04 18:25:12 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)