【发布时间】:2015-10-24 08:32:29
【问题描述】:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inventory;
import java.net.InetAddress;
import java.sql.Connection;
import java.sql.DriverManager;
/**
*
* @author Imantha
*/
public class dbcon {
public static Connection createmyConnection() throws Exception{
InetAddress ip=InetAddress.getLocalHost();
String s=ip.getHostAddress();
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localHost:3306/inventory","root","123");
return c;
}
}
我如何使用从 InerAddress 中找到的 ip 地址通过 JDBC 与 MySQL 连接?
我想替换本地主机并添加s(捕获ip地址)
【问题讨论】: